25 lines
680 B
C#
25 lines
680 B
C#
using System.Net;
|
|
|
|
namespace Flypaper.Core.Networking;
|
|
|
|
public static class PrivateNetworks
|
|
{
|
|
private static readonly IPNetwork[] Networks =
|
|
[
|
|
IPNetwork.Parse("127.0.0.0/8"),
|
|
IPNetwork.Parse("10.0.0.0/8"),
|
|
IPNetwork.Parse("172.16.0.0/12"),
|
|
IPNetwork.Parse("192.168.0.0/16"),
|
|
IPNetwork.Parse("169.254.0.0/16"),
|
|
IPNetwork.Parse("::1/128"),
|
|
IPNetwork.Parse("fc00::/7"),
|
|
IPNetwork.Parse("fe80::/10")
|
|
];
|
|
|
|
public static bool Contains(IPAddress address)
|
|
{
|
|
var ip = address.IsIPv4MappedToIPv6 ? address.MapToIPv4() : address;
|
|
return Networks.Any(network => network.Contains(ip));
|
|
}
|
|
}
|