示例#1
0
文件: usb.py 项目: polybassa/scapy-1
                data[netw_name] = NetworkInterface(self, if_data)
            return data

        def l2socket(self):
            return conf.USBsocket

        l2listen = l2socket

        def l3socket(self):
            raise ValueError("No L3 available for USBpcap !")

        def _format(self, dev, **kwargs):
            """Returns a tuple of the elements used by show()"""
            return (str(dev.index), dev.name, dev.network_name)

    IFACES.register_provider(UsbpcapInterfaceProvider)

    def get_usbpcap_devices(iface, enabled=True):
        """Return a list of devices on an USBpcap interface"""
        _usbpcap_check()
        devices = _extcap_call(
            conf.prog.usbpcapcmd,
            ["--extcap-interface", iface, "--extcap-config"], "value",
            ["value", "display", "enabled"])
        devices = [(dev[0], dev[1], dev[2] == "true") for dev in devices]
        if enabled:
            return [dev for dev in devices if dev[2]]
        return devices

    class USBpcapSocket(SuperSocket):
        """
示例#2
0
            ifflags = FlagValue(ifflags, _iff_flags)
            if_data = {
                "name": i,
                "network_name": i,
                "description": i,
                "flags": ifflags,
                "index": index,
                "ip": ip,
                "ips": [x[0] for x in ips if x[2] == i] + [ip] if ip else [],
                "mac": mac
            }
            data[i] = NetworkInterface(self, if_data)
        return data


IFACES.register_provider(LinuxInterfaceProvider)

if os.uname()[4] in ['x86_64', 'aarch64']:
    def get_last_packet_timestamp(sock):
        ts = ioctl(sock, SIOCGSTAMP, "1234567890123456")
        s, us = struct.unpack("QQ", ts)
        return s + us / 1000000.0
else:
    def get_last_packet_timestamp(sock):
        ts = ioctl(sock, SIOCGSTAMP, "12345678")
        s, us = struct.unpack("II", ts)
        return s + us / 1000000.0


def _flush_fd(fd):
    if hasattr(fd, 'fileno'):
示例#3
0
            # Close the file descriptor
            os.close(fd)

    def load(self):
        from scapy.fields import FlagValue
        data = {}
        ips = in6_getifaddr()
        for ifname, index in _get_ifindex_list():
            try:
                ifflags = _get_if_flags(ifname)
                mac = scapy.utils.str2mac(get_if_raw_hwaddr(ifname)[1])
                ip = inet_ntop(socket.AF_INET, get_if_raw_addr(ifname))
            except Scapy_Exception:
                continue
            ifflags = FlagValue(ifflags, _iff_flags)
            if_data = {
                "name": ifname,
                "network_name": ifname,
                "description": ifname,
                "flags": ifflags,
                "index": index,
                "ip": ip,
                "ips": [x[0] for x in ips if x[2] == ifname] + [ip],
                "mac": mac
            }
            data[ifname] = NetworkInterface(self, if_data)
        return data


IFACES.register_provider(BPFInterfaceProvider)