pointeman
asked on
IPHostEntry GetHostEntry IPv6 or IPv4 ?
I've been using the following code to return an IP (v4) from a host name. However, this doesn't work on Vista IPv6 address returns.
Q. How can I change this code to detect the OS and find the IP per Host name accordingly?
private IPAddress GetIP()
{
IPAddress thisIp = null;
string strHostName = Dns.GetHostName();
IPHostEntry iphostentry = Dns.GetHostEntry(strHostNa me);// Find host name
foreach (IPAddress ipAddress in iphostentry.AddressList)// Grab the first IP addresses
{
thisIp = ipAddress;
}
return thisIp;
}
Q. How can I change this code to detect the OS and find the IP per Host name accordingly?
private IPAddress GetIP()
{
IPAddress thisIp = null;
string strHostName = Dns.GetHostName();
IPHostEntry iphostentry = Dns.GetHostEntry(strHostNa
foreach (IPAddress ipAddress in iphostentry.AddressList)//
{
thisIp = ipAddress;
}
return thisIp;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Q. Will every Vista, Seven, etc O/S return an IPv4 upon request?