Skip to content

Instantly share code, notes, and snippets.

@adamcrosby
Last active November 19, 2016 14:12
Show Gist options
  • Save adamcrosby/8465762b3516dd4296d5 to your computer and use it in GitHub Desktop.
Save adamcrosby/8465762b3516dd4296d5 to your computer and use it in GitHub Desktop.
#!/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