相当于 C# 中的 isSiteLocalAddress
本文关键字:isSiteLocalAddress 中的 相当于 | 更新日期: 2023-09-27 18:33:46
在java中有一个方法inetaddress.isSiteLocalAddrress来确定IP地址是否与site的IP地址在相同的范围内,我们在C#中是否有任何等效的方法
private bool isIPLocal(IPAddress ipaddress)
{
String[] straryIPAddress = ipaddress.ToString().Split(new String[] { "." }, StringSplitOptions.RemoveEmptyEntries);
int[] iaryIPAddress = new int[] { int.Parse(straryIPAddress[0]), int.Parse(straryIPAddress[1]), int.Parse(straryIPAddress[2]), int.Parse(straryIPAddress[3]) };
if (iaryIPAddress[0] == 10 || (iaryIPAddress[0] == 192 && iaryIPAddress[1] == 168) || (iaryIPAddress[0] == 172 && (iaryIPAddress[1] >= 16 && iaryIPAddress[1] <= 31)))
{
return true;
}
else
{
// IP Address is "probably" public. This doesn't catch some VPN ranges like OpenVPN and Hamachi.
return false;
}
}