From 5e7624b8eaee0c0e75599088ebf0ae46c148573f Mon Sep 17 00:00:00 2001 From: Guillaume Valadon <guillaume@valadon.net> Date: Mon, 2 Jan 2017 17:49:59 +0100 Subject: [PATCH] get_if_raw_addr(): unified behavior --- scapy/arch/bpf/core.py | 7 ++++--- scapy/arch/pcapdnet.py | 8 +++++++- test/regression.uts | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scapy/arch/bpf/core.py b/scapy/arch/bpf/core.py index a8339b2a..7360506d 100644 --- a/scapy/arch/bpf/core.py +++ b/scapy/arch/bpf/core.py @@ -53,12 +53,14 @@ def get_if_raw_addr(ifname): try: fd = os.popen("%s %s" % (conf.prog.ifconfig, ifname)) except OSError, msg: - raise Scapy_Exception("Failed to execute ifconfig: (%s)" % msg) + warning("Failed to execute ifconfig: (%s)" % msg) + return "\0\0\0\0" # Get IPv4 addresses addresses = [l for l in fd.readlines() if l.find("netmask") >= 0] if not addresses: - raise Scapy_Exception("No IPv4 address found on %s !" % ifname) + warning("No IPv4 address found on %s !" % ifname) + return "\0\0\0\0" # Pack the first address address = addresses[0].split(' ')[1] @@ -78,7 +80,6 @@ def get_if_raw_hwaddr(ifname): try: fd = os.popen("%s %s" % (conf.prog.ifconfig, ifname)) except OSError, msg: - warning("Failed to execute ifconfig: (%s)" % msg) raise Scapy_Exception("Failed to execute ifconfig: (%s)" % msg) # Get MAC addresses diff --git a/scapy/arch/pcapdnet.py b/scapy/arch/pcapdnet.py index 77e18b47..f90fdacb 100644 --- a/scapy/arch/pcapdnet.py +++ b/scapy/arch/pcapdnet.py @@ -520,7 +520,13 @@ if conf.use_dnet: def get_if_raw_addr(ifname): i = dnet.intf() - return i.get(ifname)["addr"].data + try: + return i.get(ifname)["addr"].data + except OSError: + warning("No MAC address found on %s !" % ifname) + return "\0\0\0\0" + + def get_if_list(): return [i.get("name", None) for i in dnet.intf()] diff --git a/test/regression.uts b/test/regression.uts index 16baaeb9..506adfc4 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -34,6 +34,8 @@ get_if_raw_hwaddr(conf.iface) get_if_raw_addr(conf.iface).encode("hex") +get_if_raw_addr("dummy0") + get_if_list() = Test read_routes6() - default output @@ -57,7 +59,7 @@ if len(routes6): else: False else: - #Â IPv6 seems disabled. Force a route to ::1 + # IPv6 seems disabled. Force a route to ::1 conf.route6.routes.append(("::1", 128, "::", LOOPBACK_NAME, ["::1"])) True -- GitLab