diff options
author | Pierre Lalet <pierre@droids-corp.org> | 2018-01-21 21:44:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-21 21:44:30 +0100 |
commit | db22426d4934bad5a67ca68a7499c3d0a202ce0f (patch) | |
tree | cae5a06ebf73f99f3e92a9f809dd42a25687cc41 | |
parent | 9ff2533d6fd1e7bdaf60fae017fe7eeda7cf930c (diff) | |
parent | 986eaf14713bdc3081ec332b928c99f4dd18ec0c (diff) | |
download | scapy-db22426d4934bad5a67ca68a7499c3d0a202ce0f.tar.gz |
Merge pull request #1067 from gpotter2/win-static-py3
Static access to LOOPBACK_INTERFACE
-rw-r--r-- | scapy/route.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/scapy/route.py b/scapy/route.py index ca1ca3dc..4a23bbdb 100644 --- a/scapy/route.py +++ b/scapy/route.py @@ -11,8 +11,8 @@ Routing and handling of network interfaces. from __future__ import absolute_import +import scapy.consts from scapy.config import conf -from scapy.consts import WINDOWS, LOOPBACK_INTERFACE from scapy.error import Scapy_Exception, warning from scapy.modules import six from scapy.utils import atol, ltoa, itom, pretty_list @@ -97,7 +97,7 @@ class Route: for i, route in enumerate(self.routes): net, msk, gw, iface, addr, metric = route - if WINDOWS: + if scapy.consts.WINDOWS: if iff.guid != iface.guid: continue elif iff != iface: @@ -114,7 +114,7 @@ class Route: self.invalidate_cache() new_routes=[] for rt in self.routes: - if WINDOWS: + if scapy.consts.WINDOWS: if iff.guid == rt[3].guid: continue elif iff == rt[3]: @@ -157,14 +157,14 @@ class Route: aa = atol(a) if aa == dst: pathes.append( - (0xffffffff, 1, (LOOPBACK_INTERFACE, a, "0.0.0.0")) + (0xffffffff, 1, (scapy.consts.LOOPBACK_INTERFACE, a, "0.0.0.0")) ) if (dst & m) == (d & m): pathes.append((m, me, (i,a,gw))) if not pathes: if verbose: warning("No route found (no default route?)") - return LOOPBACK_INTERFACE, "0.0.0.0", "0.0.0.0" + return scapy.consts.LOOPBACK_INTERFACE, "0.0.0.0", "0.0.0.0" # Choose the more specific route # Sort by greatest netmask pathes.sort(key=lambda x: x[0], reverse=True) @@ -181,7 +181,7 @@ class Route: for net, msk, gw, iface, addr, metric in self.routes: if net == 0: continue - if WINDOWS: + if scapy.consts.WINDOWS: if iff.guid != iface.guid: continue elif iff != iface: @@ -194,7 +194,10 @@ conf.route=Route() iface = conf.route.route("0.0.0.0", verbose=0)[0] -if (iface.name if hasattr(iface, "name") else iface) == LOOPBACK_INTERFACE: +# Warning: scapy.consts.LOOPBACK_INTERFACE must always be used statically, because it +# may be changed by scapy/arch/windows during execution + +if (iface.name if hasattr(iface, "name") else iface) == scapy.consts.LOOPBACK_INTERFACE: from scapy.arch import get_working_if conf.iface = get_working_if() else: |