How do I get the subnet value from an IP Address. For eg, we can do below in Python. (But how about Java?)
interface = ipaddress.IPv4Interface('11.22.104.0/0.0.0.255')
value = interface.with_prefixlen
Output of value = 11.22.104.0/24
Basically, I need a function to convert 0.0.0.255 into /24. Thanks.
Edit
-Java 7 is used.
With Guava:
With Java 8:
With Java 7:
The value of
slash
will be 24.