Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions websocket-sharp/Ext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -1510,6 +1513,30 @@ public static bool IsLocal (this System.Net.IPAddress address)
return false;
}

/// <summary>
/// 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
/// </summary>
/// <param name="address">The IP address to check</param>
/// <returns>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;
}
}

/// <summary>
/// Determines whether the specified string is <see langword="null"/> or
/// an empty string.
Expand Down