(ip, net)
return ret
Is an address in a network
Is an address in a network
Is an address in a network
def addressInNetwork(ip, net):
    "Is an address in a network"
    ret = False
    try:
        ipaddr = struct.unpack('!I', socket.inet_aton(ip))[0]
        netaddr, bits = net.split('/')
        netmask = struct.unpack('!I', socket.inet_aton(netaddr))[
            0] & ((2 << int(bits)-1) - 1)
        ret = ipaddr & netmask == netmask
    except Exception as e:
        ret = False
    return ret
def addressInNetwork ( ip , net ) : ret = False try : ipaddr = struct . unpack ( '!I' , socket . inet_aton ( ip ) ) [ 0 ] netaddr , bits = net . split ( '/' ) netmask = struct . unpack ( '!I' , socket . inet_aton ( netaddr ) ) [ 0 ] & ( ( 2 << int ( bits ) - 1 ) - 1 ) ret = ipaddr & netmask == netmask except Exception as e : ret = False return ret