Edamame Edamame - 2 months ago 17
Python Question

python: ipaddress package output not consistent with CIDR website

I am converting some CIDR using python ipaddress package like:

import ipaddress
net4 = ipaddress.ip_network(u'')
for x in net4.hosts():

The first_ip output from the above code is
, while the last_ip from the above code is

However, if I use the website: http://www.ipaddressguide.com/cidr to do the conversion: the first_ip becomes
while the last_ip becomes

Does anyone know why the results are different and which one is correct? Thanks!


The last address will be the subnet's broadcast address, so you can't give it to a host, and the first is the network's address itself, which is also not assigned to hosts. So both sources are correct, they just tell you different things: the python routine gives you IPs suitable for hosts, while the web page gives you all IPs in the range, including network and broadcast.