Created
October 2, 2015 06:50
-
-
Save PSJoshi/5a8a9325cca386afd77b to your computer and use it in GitHub Desktop.
python:Check if ip is in a network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>>from netaddr import IPNetwork, IPAddress | |
| >>>if IPAddress("192.168.0.1") in IPNetwork("192.168.0.0/24"): | |
| print "Yes!" | |
| >>>import ipaddress | |
| >>> ipaddress.ip_address('192.168.0.1') in ipaddress.ip_network('192.168.0.0/24') | |
| True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment