From 241205e5b064f1a546af90e184a0580996ef9b5d Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Tue, 26 Apr 2011 10:53:58 +0200 Subject: [PATCH] Only get network interfaces that are up. --- linkcheck/dns/resolver.py | 4 ++-- linkcheck/network/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) 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