Last active
November 19, 2016 14:12
-
-
Save adamcrosby/8465762b3516dd4296d5 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
def ip2int(ip): | |
(f,s,t,l)=ip.split('.') | |
return (int(f)*16777216)+(int(s)*65536)+(int(t)*256)+int(l) | |
def ipInNet(ip, network, masklength): | |
mask = 0xFFFFFFFF << (32 - int(masklength)) | |
if (ip2int(ip) & mask) == (ip2int(network) & mask): | |
return True | |
else: | |
return False | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment