Java code/* determine whether it is an intranet IP */public static Boolean isinnerip (string IPaddress ){
Boolean isinnerip = false;
Long ipnum = getipnum (IPaddress );
/**
Private IP: Class A 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
Of course, the 127 CIDR block is the loopback address.
**/
Long abegin = getipnum ("10.0.0.0 ");
Long aend = getipnum ("10.20.255 ");
Long bbegin = getipnum ("172.16.0.0 ");
Long bend = getipnum ("172.31.20.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;
}
Java code/* Get IP number */
Private Static long getipnum (string IPaddress ){
String [] IP = IPaddress. Split ("//.");
Long A = integer. parseint (IP [0]);
Long B = integer. parseint (IP [1]);
Long c = integer. parseint (IP [2]);
Long d = integer. parseint (IP [3]);
Long ipnum = A * 256*256*256 + B * 256*256 + C * 256 + D;
Return ipnum;
}
Java code
Private Static Boolean isinner (long userip, long begin, long end ){
Return (userip> = begin) & (userip <= END );
}