<summary>
Determine if the IP address is an intranet IP address
</summary>
<param name= "ipAddress" >ip address string </param>
<returns></returns>
public static bool Isinnerip (String ipAddress)
{
BOOL Isinnerip = false;
Long Ipnum = Getipnum (ipAddress);
/**
Private Ip:a class 10.0.0.0-10.255.255.255
Class B 172.16.0.0-172.31.255.255
Class C 192.168.0.0-192.168.255.255
And, of course, 127 of this network segment is the loopback address.
**/
Long Abegin = Getipnum ("10.0.0.0");
Long aend = Getipnum ("10.255.255.255");
Long Bbegin = Getipnum ("172.16.0.0");
Long bEnd = Getipnum ("172.31.255.255");
Long Cbegin = Getipnum ("192.168.0.0");
Long cend = Getipnum ("192.168.255.255");
Isinnerip = Isinner (Ipnum, Abegin, aend) | | Isinner (Ipnum, Bbegin, bEnd) | | Isinner (Ipnum, Cbegin, cend) | | Ipaddress.equals ("127.0.0.1");
return isinnerip;
}
<summary>
Convert IP address to long number
</summary>
<param name= "ipAddress" >ip address string </param>
<returns></returns>
private static Long Getipnum (String ipAddress)
{
string[] IP = ipaddress.split ('. ');
Long a = Int. Parse (Ip[0]);
Long B = Int. Parse (ip[1]);
Long c = Int. Parse (ip[2]);
Long d = Int. Parse (Ip[3]);
Long Ipnum = A * * * * * * * * * * * * * * * * * * * + * * * * + * * + + D;
return ipnum;
}
<summary>
Determine if the IP address of the user is converted to long after the IP address of the intranet is in range
</summary>
<param name= "Userip" ></param>
<param name= "Begin" ></param>
<param name= "End" ></param>
<returns></returns>
private static bool Isinner (long userip, long begin, Long end)
{
return (Userip >= begin) && (Userip <= end);
}
C # IP internal and external network judgment