Programming in C#: Get IP address through c# (in IPv4 value) on newest questions tagged c# – Stack Overflow
I try the following code to get my IP address, in XP, it returns the IP address V4 format,
but when I do it in my system(windows 7), it return the ip address in v6 format.
How do to solve this?
Code
try
{
//iphostname = Dns.GetHostName(); // Resolving Host name
IPHostEntry ipentry = Dns.GetHostEntry(hostLabel.Text);
IPAddress[] addr = ipentry.AddressList;// Resolving IP Addresses
for (int i = 0; i < addr.Length; i++)
{
try
{
ipLabel.Text = Convert.ToString(addr[i]) + "\r\n";
}
catch
{
ipLabel.Text += "IP Address | " + "\r\n";
}
}
}
catch
{
//richTextBox1.Text += "Hostname | " + "\r\n";
}
See Answers
source: http://stackoverflow.com/questions/11880303/get-ip-address-through-c-sharp-in-ipv4-value
Programming in C#: programming-in-c
Recent Comments