Skip to content

Commit a2fd46d

Browse files
committed
Check if the network interface still exists
1 parent 23ff728 commit a2fd46d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

scapy/arch/linux.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,17 @@ def load(self):
414414
data = {}
415415
ips = in6_getifaddr()
416416
for i in _get_if_list():
417-
ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
418-
index = get_if_index(i)
419-
mac = scapy.utils.str2mac(
420-
get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
421-
)
422-
ip = None # type: Optional[str]
423-
ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
417+
try:
418+
ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
419+
index = get_if_index(i)
420+
mac = scapy.utils.str2mac(
421+
get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
422+
)
423+
ip = None # type: Optional[str]
424+
ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
425+
except IOError:
426+
warning("Interface %s does not exist!", i)
427+
continue
424428
if ip == "0.0.0.0":
425429
ip = None
426430
ifflags = FlagValue(ifflags, _iff_flags)

0 commit comments

Comments
 (0)