如何判断ip的范围
如何判断ip 192.168.0.5是否在 192.168.0.0-----192.168.0.68这个范围..用程序如何实现这个功能..
public class Test {
public static boolean isRightIP(String ip) {
if (ip == null || !ip.startsWith("192.168.0.")) {
return false;
} else {
try {
int addr = Integer.parseInt(ip.substring(ip.lastIndexOf('.')+1));
if (addr >= 0 && addr <= 68)
return true;
else
return false;
} catch(Exception e) {
return false;
}
}
}
public static void main(String[] args) {
String a = "192.168.0.12";
if (isRightIP(a))
System.out.println(a + " is OK!");
else
System.out.println(a + " is bad!");
}
}