diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index c25e89dca..8c2792458 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -1499,6 +1499,9 @@ public static bool IsLocal (this System.Net.IPAddress address) return true; } + if (address.IsInternal()) + return true; + var name = System.Net.Dns.GetHostName (); var addrs = System.Net.Dns.GetHostAddresses (name); @@ -1510,6 +1513,30 @@ public static bool IsLocal (this System.Net.IPAddress address) return false; } + /// + /// An extension method to determine if an IP address is internal + /// Class A Private IP Range: 10.0.0.0 -> 10.255.255.255 + /// Class B Private IP Range: 172.16.0.0 -> 172.31.255.255 + /// Class C Private IP Range: 192.168.0.0 -> 192.168.255.25 + /// + /// The IP address to check + /// Returns true if the IP matches the internal ranges, false if not/returns> + public static bool IsInternal(this System.Net.IPAddress address) + { + byte[] bytes = address.GetAddressBytes(); + switch( bytes[ 0 ] ) + { + case 10: + return true; + case 172: + return bytes[ 1 ] < 32 && bytes[ 1 ] >= 16; + case 192: + return bytes[ 1 ] == 168; + default: + return false; + } + } + /// /// Determines whether the specified string is or /// an empty string.