def address_in_network(ip, net):
 ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0]
 (netaddr, bits) = net.split('/')
 netmask = struct.unpack('=L', socket.inet_aton(dotted_netmask(int(bits))))[0]
 network = (struct.unpack('=L', socket.inet_aton(netaddr))[0] & netmask)
 return ((ipaddr & netmask) == (network & netmask))

def address_in_network ( ip , net ) : ipaddr = struct . unpack ( '=L' , socket . inet_aton ( ip ) ) [ 0 ] ( netaddr , bits ) = net . split ( '/' ) netmask = struct . unpack ( '=L' , socket . inet_aton ( dotted_netmask ( int ( bits ) ) ) ) [ 0 ] network = ( struct . unpack ( '=L' , socket . inet_aton ( netaddr ) ) [ 0 ] & netmask ) return ( ( ipaddr & netmask ) == ( network & netmask ) )
this function allows you to check if on ip belongs to a network subnet example: returns true if ip = 192 .