def is_in_subnet(ip, mask):
 ipaddr = int(''.join([('%02x' % int(x)) for x in ip.split('.')]), 16)
 (netstr, bits) = mask.split('/')
 netaddr = int(''.join([('%02x' % int(x)) for x in netstr.split('.')]), 16)
 mask = ((4294967295 << (32 - int(bits))) & 4294967295)
 return ((ipaddr & mask) == (netaddr & mask))

def is_in_subnet ( ip , mask ) : ipaddr = int ( '' . join ( [ ( '%02x' % int ( x ) ) for x in ip . split ( '.' ) ] ) , 16 ) ( netstr , bits ) = mask . split ( '/' ) netaddr = int ( '' . join ( [ ( '%02x' % int ( x ) ) for x in netstr . split ( '.' ) ] ) , 16 ) mask = ( ( 4294967295 << ( 32 - int ( bits ) ) ) & 4294967295 ) return ( ( ipaddr & mask ) == ( netaddr & mask ) )
check if a given ip address is lies within the given netmask true if ip falls within mask false otherwise .