L
Lars Fastrup
Hi,
given a host name, how can you i C# determine with 100% certainty if
it actually represents the local host? I am talking about DNS aliases
here.
I have tried the following, which seems to work in most cases. But it
unfortunately fails at a few customer installations:
public bool IsLocalHost(string hostName)
{
IPHostEntry localhost = Dns.GetHostByName(Environment.MachineName);
IPHostEntry hostInfo = Dns.GetHostByName(hostName);
foreach (IPAddress localhostAddress in localhost.AddressList)
{
foreach (IPAddress hostAddress in hostInfo.AddressList)
{
if (localhostAddress.Equals(hostAddress)) return true;
}
}
return false;
}
Any ideas?
Regards
Lars Fastrup
Navigo Systems
www.navigosystems.com
given a host name, how can you i C# determine with 100% certainty if
it actually represents the local host? I am talking about DNS aliases
here.
I have tried the following, which seems to work in most cases. But it
unfortunately fails at a few customer installations:
public bool IsLocalHost(string hostName)
{
IPHostEntry localhost = Dns.GetHostByName(Environment.MachineName);
IPHostEntry hostInfo = Dns.GetHostByName(hostName);
foreach (IPAddress localhostAddress in localhost.AddressList)
{
foreach (IPAddress hostAddress in hostInfo.AddressList)
{
if (localhostAddress.Equals(hostAddress)) return true;
}
}
return false;
}
Any ideas?
Regards
Lars Fastrup
Navigo Systems
www.navigosystems.com