Was wondering if anyone could help me out here. I don’t dont much with c# but its easy for what im trying to do.
I am making a small application that will take in the hostname on my network and then return the full ipaddress(ipv4) ….From there i have options to ping/vnc/telnet…etc.
My question lies here… I am using GetHostEntry to return the ip address. Then I want to store the IP into a variable, and change the last octet. I figured a simple sting.split('.') would be the answer, but I can’t convert the IP to a string because the source is not a string. Any ideas?
Here is my Method to get the IP address, its just the basic GetHostEntry method:
IPHostEntry host = Dns.GetHostEntry( hostname );
Console.WriteLine( "GetHostEntry({0}) returns: {1}", hostname, host );
// This will loop though the IPAddress system array and echo out
// the results to the console window
foreach ( IPAddress ip in host.AddressList )
{
Console.WriteLine( " {0}", ip );
}
Here’s a rather brittle method that relies on the byte order of your machine and, obviously, the family of the provided address.