diff --git a/scapy/arch/bpf/core.py b/scapy/arch/bpf/core.py index a8339b2ab620abfe2753018b2ed9d2d4d3cf7429..7360506d578179ae21ea7292cbe0018a3093418a 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 77e18b4720e073196263993b2b00b25cfc164e02..f90fdacb73e218272d3fb0bbdfcda9c627571ca1 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 16baaeb9853194e35bc764465f34a5fbfebcf24f..506adfc4c296091fc6c210ddf9be7c27338eac99 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