Only get network interfaces that are up.

This commit is contained in:
Bastian Kleineidam 2011-04-26 10:53:58 +02:00
parent 6a135dd79c
commit 241205e5b0
2 changed files with 5 additions and 3 deletions

View file

@ -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:

View file

@ -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