Try this:
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
string localComputerName = Dns.GetHostName();
public static bool IsLocalIpAddress(string host)
{
try
{
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress hostIP in hostIPs)
{
if (IPAddress.IsLoopback(hostIP)) return true;
foreach (IPAddress localIP in localIPs)
{
if (hostIP.Equals(localIP)) return true;
}
}
}
catch { }
return false;
}
IsLocalIpAddress("localhost");
IsLocalIpAddress("127.0.0.1");
IsLocalIpAddress("MyNotebook");
IsLocalIpAddress("192.168.0.1");
IsLocalIpAddress("NonExistingName");
IsLocalIpAddress("99.0.0.1");