0

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')
Zain Khan
3,8233 gold badges37 silver badges54 bronze badges
asked Jan 3, 2012 at 7:01
0

2 Answers 2

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
answered Jan 3, 2012 at 7:52
Sign up to request clarification or add additional context in comments.

8 Comments

I tried to look for ipaddr doc packages.python.org/ipaddr can't seem to find usage of IPAddress/IPNetwork, or is it the wrong one what I was looking at..
I just using easy_install ipaddr and looking help(ipaddr).
That would validate IP in the range of 10.0.0.193 to 10.0.0.198?
If I would like to validate IP in the range of 10.0.0.195 to 10.0.0.200 for example, do I really have to convert it to CIDR beforehand?
Also you can use construction like IPAddress('10.0.0.194') < IPAddress(my_ip_string) < IPAddress('10.0.0.200')
|
1

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.

answered Jan 3, 2012 at 8:04

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.