diff --git a/linkcheck/dns/resolver.py b/linkcheck/dns/resolver.py index a26a0445..45726785 100644 --- a/linkcheck/dns/resolver.py +++ b/linkcheck/dns/resolver.py @@ -393,8 +393,8 @@ class Resolver(object): return [] from linkcheck.network import IfConfig ifc = IfConfig() - return [ifc.getAddr(iface) for iface in ifc.getInterfaceList() \ - if ifc.isUp(iface)] + return [ifc.getAddr(iface) + for iface in ifc.getInterfaceList(flags=IfConfig.IFF_UP)] def add_addrinfo (self, host, interface=False): try: diff --git a/linkcheck/network/__init__.py b/linkcheck/network/__init__.py index 935fdd89..c9fa4813 100644 --- a/linkcheck/network/__init__.py +++ b/linkcheck/network/__init__.py @@ -64,7 +64,7 @@ class IfConfig (object): return None return socket.inet_ntoa(result[20:24]) - def getInterfaceList (self): + def getInterfaceList (self, flags=0): """Get all interface names in a list.""" if sys.platform == 'darwin': command = ['ifconfig', '-l'] @@ -100,6 +100,8 @@ class IfConfig (object): name = struct.unpack("16s%ds" % (self.ifr_size-16), ifconf)[0] name = name.split('\0', 1)[0] if name: + if flags and not (self.getFlags(name) & flags): + continue iflist.append(name) i += self.ifr_size return iflist