I am working on code where I need to find whether the ipAddress belongs to Private Range or not. Any suggestions will be appreciated.
UPDATED-
This is my method-
if(isPrivateIPAddress(ipAddress)) {
//do whatever you want
}
private static boolean isPrivateIPAddress(InetAddress address, String range) {
// TODO Auto-generated method stub
String ipAddress = address.getHostAddress();
return ipAddress.startsWith( range );
}
So I am not sure what is the address we need to pass in the above if loop.
Take a look at this method, you can determine if an IP address starts with the defined private range:
Sample invocations:
Sample program: