MCPcopy Index your code
hub / github.com/secdev/scapy / get_working_if

Function get_working_if

scapy/interfaces.py:377–398  ·  view source on GitHub ↗

Return an interface that works

()

Source from the content-addressed store, hash-verified

375
376
377def get_working_if():
378 # type: () -> Optional[NetworkInterface]
379 """Return an interface that works"""
380 # return the interface associated with the route with smallest
381 # mask (route by default if it exists)
382 routes = conf.route.routes[:]
383 routes.sort(key=lambda x: x[1])
384 ifaces = (x[3] for x in routes)
385 # First check the routing ifaces from best to worse,
386 # then check all the available ifaces as backup.
387 for ifname in itertools.chain(ifaces, conf.ifaces.values()):
388 try:
389 iface = conf.ifaces.dev_from_networkname(ifname) # type: ignore
390 if iface.is_valid():
391 return iface
392 except ValueError:
393 pass
394 # There is no hope left
395 try:
396 return conf.ifaces.dev_from_networkname(conf.loopback_name)
397 except ValueError:
398 return None
399
400
401def get_working_ifaces():

Callers 1

load_confifaceMethod · 0.70

Calls 3

dev_from_networknameMethod · 0.80
is_validMethod · 0.80
valuesMethod · 0.45

Tested by

no test coverage detected