Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2014 16:13
What would you like to do?
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