Exemplo n.º 1
0
def get_ipv6_link_local(iface):
    lla = [
        l[0] for l in sca.in6_getifaddr()
        if l[2] == iface and l[0].startswith("fe80")
    ]
    if len(lla) > 0:
        return lla[0]
Exemplo n.º 2
0
def iface(ctx, interface):
    """
    Monitor a specific network interface
    """
    # See scapy.arch.linux.in6_getifaddr:
    # Returns a list of 3-tuples of the form (addr, scope, iface) where
    # 'addr' is the address of scope 'scope' associated to the interface
    # 'ifcace'.
    interfaces = [x[-1] for x in in6_getifaddr()]
    if interface not in interfaces:
        # No exception to catch!
        # SniffSource will fail silently if interface doesn't exist.
        import sys
        click.echo('Interface "{}" not found.'.format(interface))
        click.echo('Peekapp found the following:\n\t{}'.format(
            '\n\t'.join(interfaces)))
        sys.exit(1)

    source = main(blacklist=ctx.obj['blacklist'],
                  logfile=ctx.obj['logfile'],
                  alert_timeout=ctx.obj['alert_timeout'],
                  port_scan=ctx.obj['port_scan'])
    try:
        # For some reason, click calls this function a second time...
        # ...but with interface as <type 'unicode'>...
        # ...which breaks struct.pack("16s16x", iff) in scapy/arch/common.py
        sniff(iface=str(interface), prn=source.push)
    except KeyboardInterrupt:
        click.echo('\n\tHalting on keyboard interrupt.')
Exemplo n.º 3
0
def get_if_addr6(intf, address_type):
    """Returns the Ipv6 address from a given local interface.

    Returns the desired IPv6 address from the interface 'intf' in human
    readable form. The address type is indicated by the IPv6 constants like
    IPV6_ADDR_LINKLOCAL, IPV6_ADDR_GLOBAL, etc. If no address is found,
    None is returned.

    Args:
        intf: desired interface name
        address_type: addrees typle like LINKLOCAL or GLOBAL

    Returns:
        Ipv6 address of the specified interface in human readable format
    """
    for if_list in scapy.in6_getifaddr():
        if if_list[2] == intf and if_list[1] == address_type:
            return if_list[0]

    return None
Exemplo n.º 4
0
 def reload(self):
     """Reload tables from current state"""
     self.ifhwaddr = get_if_hwaddr(self.iface)
     lladdresses = [
         addr for addr, scope, iface in in6_getifaddr()
         if scope == IPV6_ADDR_LINKLOCAL and iface == self.iface
     ]
     if len(lladdresses) != 1:
         raise Exception("Unable to find link-local address of {0}".format(
             self.iface))
     self.llip6addr = lladdresses[0]
     self.clear()
     for _, ip, hw in ipcmd.list_neigh(iface=self.iface):
         self[ip] = hw
     self.proxies = set()
     for _, ip in ipcmd.list_neigh_proxy(iface=self.iface):
         self.proxies.add(ip)
     self.host_routes = set()
     for _, ip in ipcmd.list_host_routes(iface=self.iface):
         self.host_routes.add(ip)