import struct
import socket


def address_in_network(ip, net):
    """
    Is an address in a network
    ip: 192.168.2.2
    net:("192.168.2.0/24",)
    """
    ipaddr = struct.unpack('=L', socket.inet_aton(ip))[0]
    for cur_net in net:
        netaddr, bits = cur_net.split('/')
        netmask = struct.unpack('=L', socket.inet_aton(netaddr))[0] & ((2 << int(bits) - 1) - 1)
        if ipaddr & netmask == netmask:
            return True
    return False