Skip to content

Instantly share code, notes, and snippets.

@athoune
Created October 31, 2014 16:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save athoune/8b88f834ae2493e5f57a to your computer and use it in GitHub Desktop.
import socket
import struct
def ip_to_long(ip):
return struct.unpack('!L', socket.inet_aton(ip))[0]
def subnet_match(ip, subnet):
lsubnet = ip_to_long(subnet)
return lsubnet == (ip_to_long(ip) & lsubnet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment