(ip, mask)
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
Check if a given IP address is lies within the given netmask
       TRUE if 'ip' falls within 'mask'
       FALSE otherwise
Check if a given IP address is lies within the given netmask TRUE if ip falls within mask FALSE otherwise
def is_in_subnet(ip, mask):
    """Check if a given IP address is lies within the given netmask
       TRUE if 'ip' falls within 'mask'
       FALSE otherwise
    """
    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 = (0xffffffff << (32 - int(bits))) & 0xffffffff
    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 = ( 0xffffffff << ( 32 - int ( bits ) ) ) & 0xffffffff return ( ipaddr & mask ) == ( netaddr & mask )