示例#1
0
def check_dhcp(ifaces, timeout=5, repeat=2):
    """Given list of ifaces. Process them in separate processes
    @ifaces - lsit of ifaces
    @timeout - timeout for scapy to wait for response
    @repeat - number of packets sended
    >>> check_dhcp(['eth1', 'eth2'])
    """
    ifaces_filtered = list(utils.filtered_ifaces(ifaces))
    if not ifaces_filtered:
        raise EnvironmentError("No valid interfaces provided.")
    pool = multiprocessing.Pool(len(ifaces_filtered)*repeat)
    return itertools.chain(*pool.map(check_dhcp_on_eth, (
        (iface, timeout) for iface in ifaces_filtered*repeat)))
示例#2
0
def check_dhcp(ifaces, timeout=5, repeat=2):
    """Given list of ifaces. Process them in separate processes
    @ifaces - lsit of ifaces
    @timeout - timeout for scapy to wait for response
    @repeat - number of packets sended
    >>> check_dhcp(['eth1', 'eth2'])
    """
    ifaces_filtered = list(utils.filtered_ifaces(ifaces))
    if not ifaces_filtered:
        raise EnvironmentError("No valid interfaces provided.")
    pool = multiprocessing.Pool(len(ifaces_filtered) * repeat)
    return itertools.chain(
        *pool.map(check_dhcp_on_eth, ((iface, timeout)
                                      for iface in ifaces_filtered * repeat)))
示例#3
0
def check_dhcp_with_vlans(config, timeout=5, repeat=2):
    """Provide config of {iface: [vlans..]} pairs
    @config - {'eth0': (100, 101), 'eth1': (100, 102)}
    """
    # vifaces - list of pairs ('eth0', ['eth0.100', 'eth0.101'])
    with utils.VlansContext(config) as vifaces:
        ifaces, vlans = zip(*vifaces)
        listeners = make_listeners(ifaces)

        for _ in xrange(repeat):
            for i in utils.filtered_ifaces(itertools.chain(ifaces, *vlans)):
                send_dhcp_discover(i)
            time.sleep(timeout)

        for l in listeners:
            for pkt in l.readpkts():
                yield utils.format_answer(scapy.Ether(pkt[1]), l.name)
示例#4
0
def check_dhcp_with_vlans(config, timeout=5, repeat=2, w_vlans=True):
    """Provide config of {iface: [vlans..]} pairs

    @config - {'eth0': (100, 101), 'eth1': (100, 102)}

    'w_vlans' flag toggles dhcp discover check for tagged interfaces;
    if it is False - the request will be sent only for real interfaces

    Before the request is sent interfaces are set (if they haven't been before)
    and after - down-ed (only those up-ed for the purpose of this checking)

    If the flag 'w_vlans' holds True but list of vlans for iface is [0],
    the check will also be performed only for real interfaces (see logic of
    utils.VlansContext context manager)
    """
    # vifaces - list of pairs ('eth0', ['eth0.100', 'eth0.101'])
    with utils.VlansContext(config) as vifaces:
        ifaces, vlans = zip(*vifaces)

        # up interfaces before making the check
        with utils.IfaceState(ifaces) as rdy_ifaces:
            listeners = make_listeners(rdy_ifaces)

            for _ in xrange(repeat):
                ifaces_to_check = (
                    itertools.chain(rdy_ifaces, *vlans)
                    if w_vlans else rdy_ifaces
                )

                for i in utils.filtered_ifaces(ifaces_to_check):
                    send_dhcp_discover(i)
                time.sleep(timeout)

            for l in listeners:
                for pkt in l.readpkts():
                    yield utils.format_answer(scapy.Ether(pkt[1]), l.name)