In .NET you can:
IPHostEntry iphostentry = Dns.GetHostEntry (Dns.GetHostName ());
Then for any host name, check if it resolves to one of the IPs in iphostEntry.AddressList
(this is an IPAddress[]).
Here is a full program that will check the host names/IP addresses passed in the command line:
using System;
using System.Net;
class Test {
static void Main (string [] args)
{
IPHostEntry iphostentry = Dns.GetHostEntry (Dns.GetHostName ());
foreach (string str in args) {
IPHostEntry other = null;
try {
other = Dns.GetHostEntry (str);
} catch {
Console.WriteLine ("Unknown host: {0}", str);
continue;
}
foreach (IPAddress addr in other.AddressList) {
if (IPAddress.IsLoopback (addr) || Array.IndexOf (iphostentry.AddressList, addr) != -1) {
Console.WriteLine ("{0} IsLocal", str);
break;
}
}
}
}
}