python - Strange result when checking if an ip address is in a network with netaddr -
when run following code in python 2.7 true of these checks.
from netaddr import * testip = '192.168.2.5' testnetwork = '192.168.3.0/23' if testip in ipnetwork(testnetwork): print "logic fail" if ipaddress(testip) in ipnetwork(testnetwork): print "logic fail" if testip in ipset([testnetwork]): print "logic fail" if ipaddress(testip) in ipset([testnetwork]): print "logic fail"
output is:
logic fail logic fail logic fail logic fail
that isn't strange result, cidr specified used called "supernetting", so:
192.168.3.0/23
effectively covers
192.168.2.1
through
192.168.3.254
giving around 512 possible addresses work /23 same network mask
255.255.254.0
which 3 gets bumped 2
to visualize, can use online subnet calculator http://mxtoolbox.com/subnetcalculator.aspx
Comments
Post a Comment