Exemplo n.º 1
0
 def _update_pcapdata(self):
     if self.is_invalid():
         return
     for i in get_if_list():
         if i.endswith(self.guid):
             self.pcap_name = i
             return
     self.invalid = True
Exemplo n.º 2
0
    def load(self):
        if not get_if_list():
            # Try a restart
            NetworkInterfaceDict._pcap_check()

        windows_interfaces = dict()
        for i in get_windows_if_list():
            # Detect Loopback interface
            if "Loopback" in i['name']:
                i['name'] = conf.loopback_name
            if i['guid']:
                if conf.use_npcap and i['name'] == conf.loopback_name:
                    i['guid'] = NPCAP_LOOPBACK_NAME
                windows_interfaces[i['guid']] = i

        index = 0
        for pcap_name, if_data in six.iteritems(conf.cache_iflist):
            name, ips, flags = if_data
            guid = _pcapname_to_guid(pcap_name)
            data = windows_interfaces.get(guid, None)
            if data:
                # Exists in Windows registry
                data['pcap_name'] = pcap_name
                data['ips'].extend(ips)
                data['flags'] = flags
                data['invalid'] = False
            else:
                # Only in [Wi]npcap
                index -= 1
                data = {
                    'name': name,
                    'pcap_name': pcap_name,
                    'description': name,
                    'win_index': index,
                    'guid': guid,
                    'invalid': False,
                    'mac': '00:00:00:00:00:00',
                    'ipv4_metric': 0,
                    'ipv6_metric': 0,
                    'ips': ips,
                    'flags': flags
                }
            # No KeyError will happen here, as we get it from cache
            self.data[guid] = NetworkInterface(data)
Exemplo n.º 3
0
    def load(self):
        if not get_if_list():
            # Try a restart
            NetworkInterfaceDict._pcap_check()

        for i in get_windows_if_list():
            try:
                interface = NetworkInterface(i)
                self.data[interface.guid] = interface
            except KeyError:
                pass

        # Remove invalid loopback interfaces (not usable)
        for key, iface in self.data.copy().items():
            if iface.ip == "127.0.0.1" and iface.is_invalid():
                del self.data[key]

        # Replace LOOPBACK_INTERFACE
        try:
            scapy.consts.LOOPBACK_INTERFACE = self.dev_from_name(
                scapy.consts.LOOPBACK_NAME,
            )
        except ValueError:
            pass
        # Support non-windows cards (e.g. Napatech)
        index = 0
        for pcap_name, if_data in six.iteritems(conf.cache_iflist):
            name, _, _ = if_data
            guid = _pcapname_to_guid(pcap_name)
            if guid not in self.data:
                index -= 1
                dummy_data = {
                    'name': name,
                    'description': "[Unknown] %s" % name,
                    'win_index': index,
                    'guid': guid,
                    'invalid': False,
                    'mac': 'ff:ff:ff:ff:ff:ff',
                    'ipv4_metric': 0,
                    'ipv6_metric': 0,
                    'ips': []
                }
                # No KeyError will happen here, as we get it from cache
                self.data[guid] = NetworkInterface(dummy_data)
Exemplo n.º 4
0
    def load(self):
        if not get_if_list():
            # Try a restart
            NetworkInterfaceDict._pcap_check()

        for i in get_windows_if_list():
            try:
                interface = NetworkInterface(i)
                self.data[interface.guid] = interface
            except KeyError:
                pass

        # Replace LOOPBACK_INTERFACE
        try:
            scapy.consts.LOOPBACK_INTERFACE = self.dev_from_name(
                scapy.consts.LOOPBACK_NAME, )
        except ValueError:
            pass
        # Support non-windows cards (e.g. Napatech)
        for name, if_data in six.iteritems(conf.cache_iflist):
            guid, ips = if_data
            guid = guid.upper().replace("\\DEVICE\\NPF_", "")
            if guid not in self.data:
                dummy_data = {
                    'name': name,
                    'description': "[Unknown] %s" % name,
                    'win_index': -1,
                    'guid': guid,
                    'invalid': False,
                    'mac': '00:00:00:00:00:00',
                    'ipv4_metric': 0,
                    'ipv6_metric': 0,
                    'ips': ips
                }
                # No KeyError will happen here, as we get it from cache
                self.data[guid] = NetworkInterface(dummy_data)