Skip to content

Commit

Permalink
update ip IsInternal() to account for missed ranges (#827)
Browse files Browse the repository at this point in the history
* update ip IsInternal() to account for missed ranges

* update with `::`
  • Loading branch information
kspearrin committed Jul 18, 2020
1 parent 3b9f625 commit 036b402
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Icons/Services/IconFetchingService.cs
Expand Up @@ -419,15 +419,28 @@ public static bool IsInternal(IPAddress ip)
{
return true;
}
else if (ip.ToString() == "::1")

var ipString = ip.ToString();
if (ipString == "::1" || ipString == "::")
{
return true;
}

// IPv6
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
return false;
return ipString.StartsWith("fc") || ipString.StartsWith("fd") ||
ipString.StartsWith("fe") || ipString.StartsWith("ff");
}

// IPv4
var bytes = ip.GetAddressBytes();
return (bytes[0]) switch
{
0 => true,
10 => true,
127 => true,
169 => bytes[1] == 254, // Cloud environments, such as AWS
172 => bytes[1] < 32 && bytes[1] >= 16,
192 => bytes[1] == 168,
_ => false,
Expand Down

0 comments on commit 036b402

Please sign in to comment.