更新时间:2023-02-22 11:50:26
一个更详细的回应是在这里:
A more detailed response is here:
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;
}
}