BF2Statistics.Net.Networking.IsLocalIpAddress C# (CSharp) Method

IsLocalIpAddress() public static method

Returns whether the IP address specified is a Local Ip Address
public static IsLocalIpAddress ( string host ) : bool
host string The ip address to check
return bool
        public static bool IsLocalIpAddress(string host)
        {
            try
            { // get host IP addresses
                IPAddress[] hostIPs = Dns.GetHostAddresses(host);

                // get local IP addresses
                IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());

                // test if any host IP equals to any local IP or to localhost
                foreach (IPAddress hostIP in hostIPs)
                {
                    // is localhost
                    if (IPAddress.IsLoopback(hostIP))
                        return true;

                    // is local address
                    foreach (IPAddress localIP in localIPs)
                        if (hostIP.Equals(localIP))
                            return true;
                }
            }
            catch { }

            return false;
        }