Given the range xxx.xxx.xxx.(195-223) Is that correct to write it in xxx.xxx.xxx.196/29 and check whether an IP is in the given network by doing
from ipaddr import IP, CIDR
#if IP('xxx.xxx.xxx.xxx') in IP('xxx.xxx.xxx.196/29') or
#if IP('xxx.xxx.xxx.xxx') in CIDR('xxx.xxx.xxx.196/29')
2 Answers 2
I didn't see IP in ipaddr, only IPAddress. May be like this?
from ipaddr import IPAdddress, IPNetwork
if IPAddress('10.0.0.195') in IPNetwork('10.0.0.196/29'):
pass
8 Comments
I haven't used the ipaddr module, but note that /29 means that your network mask is 255.255.255.248 and that you only have the latest 3 bits to address 2^3 = 8 different hosts in your network ranging from xxx.xxx.xxx.248 to xxx.xxx.xxx.255. That's outside of the range you want to check.
For more information, please have a look at the subnetwork wikipedia page.