How can I convert cidr to ip range in java ? I have used apache SubnetUtils but its ignoring first and last value of the range.
e.g for CIDR 192.168.1.0/16 output should be 192.168.0.0 to 192.168.255.255. but I am getting 192.168.0.1 to 192.168.255.254.
Please help
The SubnetUtils
class by default excludes the zeroth and last address from the range of usable "host" addresses because they are (or were, in the case of the zeroth address) used as the network broadcast address.
You need to invoke the .setInclusiveHostCount(true)
method on your SubnetUtils
instance to tell it to include those addresses within the returned range.
Actually,first and last value will be ignored beacuse of the specialitty which it carries.Theses are not general purpose IP-Addresses.The Class C
IP Addresses range will be this only.You need to read more about "Subnetting and Addressing in Class C Type IP-Addresses".
192.168.0.0
--->By convention, network routers and other gateways use 192.168.0.0 to reference a private network generically!Being private, 192.168.0.0 and all other addresses within this network cannot be used on the Internet.It's not like a general IP-Address.It is the host's IP Address(by default),you can't change it!
192.168.255.255
--->Broadcasting Address in the network,again not a general IP Address as it is used to broadcast the data to all other computers on the network!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With