Server.Misc.ServerList.HasPublicIPAddress C# (CSharp) Méthode

HasPublicIPAddress() private static méthode

private static HasPublicIPAddress ( ) : bool
Résultat bool
        private static bool HasPublicIPAddress()
        {
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

            foreach ( NetworkInterface adapter in adapters ) {
                IPInterfaceProperties properties = adapter.GetIPProperties();

                foreach ( IPAddressInformation unicast in properties.UnicastAddresses ) {
                    IPAddress ip = unicast.Address;

                    if ( !IPAddress.IsLoopback( ip ) && ip.AddressFamily != AddressFamily.InterNetworkV6 && !IsPrivateNetwork( ip ) )
                        return true;
                }
            }

            return false;

            /*
            IPHostEntry iphe = Dns.GetHostEntry( Dns.GetHostName() );

            IPAddress[] ips = iphe.AddressList;

            for ( int i = 0; i < ips.Length; ++i )
            {
                if ( ips[i].AddressFamily != AddressFamily.InterNetworkV6 && !IsPrivateNetwork( ips[i] ) )
                    return true;
            }

            return false;
            */
        }