|
| 1 | +From 7ffd8101c1e535f9c3225db2c319958a64412686 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Guillaume Valadon < [email protected]> |
| 3 | +Date: Tue, 14 Sep 2021 19:34:43 +0200 |
| 4 | +Subject: [PATCH] Check if the network interface still exists |
| 5 | + |
| 6 | +Signed-off-by: Stepan Blyschak < [email protected]> |
| 7 | +--- |
| 8 | + scapy/arch/linux.py | 18 +++++++++++------- |
| 9 | + 1 file changed, 11 insertions(+), 7 deletions(-) |
| 10 | + |
| 11 | +diff --git a/scapy/arch/linux.py b/scapy/arch/linux.py |
| 12 | +index 94fac8f0..b86e98ab 100644 |
| 13 | +--- a/scapy/arch/linux.py |
| 14 | ++++ b/scapy/arch/linux.py |
| 15 | +@@ -414,13 +414,17 @@ class LinuxInterfaceProvider(InterfaceProvider): |
| 16 | + data = {} |
| 17 | + ips = in6_getifaddr() |
| 18 | + for i in _get_if_list(): |
| 19 | +- ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0] |
| 20 | +- index = get_if_index(i) |
| 21 | +- mac = scapy.utils.str2mac( |
| 22 | +- get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1] |
| 23 | +- ) |
| 24 | +- ip = None # type: Optional[str] |
| 25 | +- ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i)) |
| 26 | ++ try: |
| 27 | ++ ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0] |
| 28 | ++ index = get_if_index(i) |
| 29 | ++ mac = scapy.utils.str2mac( |
| 30 | ++ get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1] |
| 31 | ++ ) |
| 32 | ++ ip = None # type: Optional[str] |
| 33 | ++ ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i)) |
| 34 | ++ except IOError: |
| 35 | ++ warning("Interface %s does not exist!", i) |
| 36 | ++ continue |
| 37 | + if ip == "0.0.0.0": |
| 38 | + ip = None |
| 39 | + ifflags = FlagValue(ifflags, _iff_flags) |
| 40 | +-- |
| 41 | +2.14.1 |
| 42 | + |
0 commit comments