- lxy19791111
- 等级: 初级会员
- 性别:
- 文章: 27
- 积分: 62
- 来自: 珠海
|
java 代码
- public static boolean isInnerIP(String ipAddress){
- boolean isInnerIp = false;
- long ipNum = getIpNum(ipAddress);
-
-
-
-
-
-
- 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;
- }
java 代码
- 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 代码
- private static boolean isInner(long userIp,long begin,long end){
- return (userIp>=begin) && (userIp<=end);
- }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|