(self)
Supplement more info from pypcap and the Windows registry
Supplement more info from pypcap and the Windows registry
Supplement more info from pypcap and the Windows registry
def _update_pcapdata(self):
        """Supplement more info from pypcap and the Windows registry"""
        
        # XXX: We try eth0 - eth29 by bruteforce and match by IP address, 
        # because only the IP is available in both pypcap and dnet.
        # This may not work with unorthodox network configurations and is
        # slow because we have to walk through the Windows registry.
        for n in range(30):
            guess = "eth%s" % n
            win_name = pcapdnet.pcap.ex_name(guess)
            if win_name.endswith("}"):
                try:
                    uuid = win_name[win_name.index("{"):win_name.index("}")+1]
                    keyname = r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%s" % uuid
                    try:
                        key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keyname)
                    except WindowsError:
                        log_loading.debug("Couldn't open 'HKEY_LOCAL_MACHINE\\%s' (for guessed pcap iface name '%s')." % (keyname, guess))
                        continue
                    try:    
                        fixed_ip = _winreg.QueryValueEx(key, "IPAddress")[0][0].encode("utf-8")
                    except (WindowsError, UnicodeDecodeError, IndexError):
                        fixed_ip = None
                    try:
                        dhcp_ip = _winreg.QueryValueEx(key, "DhcpIPAddress")[0].encode("utf-8")
                    except (WindowsError, UnicodeDecodeError, IndexError):
                        dhcp_ip = None
                    # "0.0.0.0" or None means the value is not set (at least not correctly).
                    # If both fixed_ip and dhcp_ip are set, fixed_ip takes precedence 
                    if fixed_ip is not None and fixed_ip != "0.0.0.0":
                        ip = fixed_ip
                    elif dhcp_ip is not None and dhcp_ip != "0.0.0.0":
                        ip = dhcp_ip
                    else:
                        continue
                except IOError:
                    continue
                else:
                    if ip == self.ip:
                        self.pcap_name = guess
                        self.win_name = win_name
                        self.uuid = uuid
                        break
        else:
            raise PcapNameNotFoundError
def _update_pcapdata ( self ) : # XXX: We try eth0 - eth29 by bruteforce and match by IP address,  # because only the IP is available in both pypcap and dnet. # This may not work with unorthodox network configurations and is # slow because we have to walk through the Windows registry. for n in range ( 30 ) : guess = "eth%s" % n win_name = pcapdnet . pcap . ex_name ( guess ) if win_name . endswith ( "}" ) : try : uuid = win_name [ win_name . index ( "{" ) : win_name . index ( "}" ) + 1 ] keyname = r"SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\%s" % uuid try : key = _winreg . OpenKey ( _winreg . HKEY_LOCAL_MACHINE , keyname ) except WindowsError : log_loading . debug ( "Couldn't open 'HKEY_LOCAL_MACHINE\\%s' (for guessed pcap iface name '%s')." % ( keyname , guess ) ) continue try : fixed_ip = _winreg . QueryValueEx ( key , "IPAddress" ) [ 0 ] [ 0 ] . encode ( "utf-8" ) except ( WindowsError , UnicodeDecodeError , IndexError ) : fixed_ip = None try : dhcp_ip = _winreg . QueryValueEx ( key , "DhcpIPAddress" ) [ 0 ] . encode ( "utf-8" ) except ( WindowsError , UnicodeDecodeError , IndexError ) : dhcp_ip = None # "0.0.0.0" or None means the value is not set (at least not correctly). # If both fixed_ip and dhcp_ip are set, fixed_ip takes precedence  if fixed_ip is not None and fixed_ip != "0.0.0.0" : ip = fixed_ip elif dhcp_ip is not None and dhcp_ip != "0.0.0.0" : ip = dhcp_ip else : continue except IOError : continue else : if ip == self . ip : self . pcap_name = guess self . win_name = win_name self . uuid = uuid break else : raise PcapNameNotFoundError