How to determine if the IP address is on the network?

I found in python ( lib ipaddress ). This is a python example.

 ip="1.232.12.3" net="1.232.12.0/20" ip in net 

true result

Can I find this in Java?

+4
source share
1 answer

What you are asking is the IP address in the given cidr range. You can write your own code to find out the beginning and end of cidr and see if the IP address falls into this range, or just use Apache Commons Net .

The SubnetUtils class does exactly what you want:

 String cidrRange = "1.232.12.0/20"; String addr = "1.232.12.3"; SubnetUtils utils = new SubnetUtils(cidrRange); boolean isInRange = utils.getInfo().isInRange(addr); 
+5
source

Source: https://habr.com/ru/post/1493392/


All Articles