Possible Duplicate:
How can I check if an ip is in a network in python
What is the easy way to match subnet to an ip address in python, so that if the ip address is in the subnet I can choose it?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Python 3.3+, you can use ipaddress module:
If your Python installation is older than 3.3, you can use this backport.
If you want to evaluate a lot of IP addresses this way, you’ll probably want to calculate the netmask upfront, like
Then, for each address, calculate the binary representation with one of
Finally, you can simply check: