mirror of https://github.com/secdev/scapy.git
[Windows] Fix import loops (#435)
This commit is contained in:
parent
78038e4c94
commit
431b04a95d
|
@ -9,41 +9,16 @@ Operating system specific functionality.
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from scapy.arch.consts import LINUX, OPENBSD, FREEBSD, NETBSD, DARWIN, \
|
from scapy.consts import LINUX, OPENBSD, FREEBSD, NETBSD, DARWIN, \
|
||||||
SOLARIS, WINDOWS, BSD, X86_64, ARM_64, LOOPBACK_NAME
|
SOLARIS, WINDOWS, BSD, X86_64, ARM_64, LOOPBACK_NAME, plt, MATPLOTLIB_INLINED, \
|
||||||
|
MATPLOTLIB_DEFAULT_PLOT_KARGS, PYX, parent_function
|
||||||
from scapy.error import *
|
from scapy.error import *
|
||||||
import scapy.config
|
import scapy.config
|
||||||
from scapy.pton_ntop import inet_pton
|
from scapy.pton_ntop import inet_pton
|
||||||
|
|
||||||
try:
|
|
||||||
from matplotlib import get_backend as matplotlib_get_backend
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
MATPLOTLIB = 1
|
|
||||||
if "inline" in matplotlib_get_backend():
|
|
||||||
MATPLOTLIB_INLINED = 1
|
|
||||||
else:
|
|
||||||
MATPLOTLIB_INLINED = 0
|
|
||||||
MATPLOTLIB_DEFAULT_PLOT_KARGS = {"marker": "+"}
|
|
||||||
# RuntimeError to catch gtk "Cannot open display" error
|
|
||||||
except (ImportError, RuntimeError):
|
|
||||||
plt = None
|
|
||||||
MATPLOTLIB = 0
|
|
||||||
MATPLOTLIB_INLINED = 0
|
|
||||||
MATPLOTLIB_DEFAULT_PLOT_KARGS = dict()
|
|
||||||
log_loading.info("Can't import matplotlib. Won't be able to plot.")
|
|
||||||
|
|
||||||
try:
|
|
||||||
import pyx
|
|
||||||
PYX=1
|
|
||||||
except ImportError:
|
|
||||||
log_loading.info("Can't import PyX. Won't be able to use psdump() or pdfdump().")
|
|
||||||
PYX=0
|
|
||||||
|
|
||||||
|
|
||||||
def str2mac(s):
|
def str2mac(s):
|
||||||
return ("%02x:"*6)[:-1] % tuple(map(ord, s))
|
return ("%02x:"*6)[:-1] % tuple(map(ord, s))
|
||||||
|
|
||||||
|
|
||||||
if not WINDOWS:
|
if not WINDOWS:
|
||||||
if not scapy.config.conf.use_pcap and not scapy.config.conf.use_dnet:
|
if not scapy.config.conf.use_pcap and not scapy.config.conf.use_dnet:
|
||||||
from scapy.arch.bpf.core import get_if_raw_addr
|
from scapy.arch.bpf.core import get_if_raw_addr
|
||||||
|
@ -71,8 +46,6 @@ def get_if_hwaddr(iff):
|
||||||
# def get_if(iff,cmd):
|
# def get_if(iff,cmd):
|
||||||
# def get_if_index(iff):
|
# def get_if_index(iff):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if LINUX:
|
if LINUX:
|
||||||
from scapy.arch.linux import *
|
from scapy.arch.linux import *
|
||||||
if scapy.config.conf.use_pcap or scapy.config.conf.use_dnet:
|
if scapy.config.conf.use_pcap or scapy.config.conf.use_dnet:
|
||||||
|
@ -93,7 +66,14 @@ elif SOLARIS:
|
||||||
from scapy.arch.solaris import *
|
from scapy.arch.solaris import *
|
||||||
elif WINDOWS:
|
elif WINDOWS:
|
||||||
from scapy.arch.windows import *
|
from scapy.arch.windows import *
|
||||||
from scapy.arch.windows.compatibility import *
|
# import only if parent is not route.py
|
||||||
|
# because compatibility.py will require route.py to work (through sendrecv.py)
|
||||||
|
parents = parent_function()
|
||||||
|
if len(parents) >= 3:
|
||||||
|
if not parents[2][1].endswith("route.py"):
|
||||||
|
from scapy.arch.windows.compatibility import *
|
||||||
|
else:
|
||||||
|
from scapy.arch.windows.compatibility import *
|
||||||
|
|
||||||
if scapy.config.conf.iface is None:
|
if scapy.config.conf.iface is None:
|
||||||
scapy.config.conf.iface = LOOPBACK_NAME
|
scapy.config.conf.iface = LOOPBACK_NAME
|
||||||
|
|
|
@ -8,7 +8,7 @@ from scapy.config import conf
|
||||||
from scapy.error import Scapy_Exception
|
from scapy.error import Scapy_Exception
|
||||||
from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER
|
from scapy.data import ARPHDR_LOOPBACK, ARPHDR_ETHER
|
||||||
from scapy.arch.common import get_if
|
from scapy.arch.common import get_if
|
||||||
from scapy.arch.consts import LOOPBACK_NAME
|
from scapy.consts import LOOPBACK_NAME
|
||||||
from scapy.utils import warning
|
from scapy.utils import warning
|
||||||
|
|
||||||
from scapy.arch.bpf.consts import *
|
from scapy.arch.bpf.consts import *
|
||||||
|
|
|
@ -12,7 +12,7 @@ from scapy.layers.inet import IP
|
||||||
from scapy.layers.inet6 import IPv6
|
from scapy.layers.inet6 import IPv6
|
||||||
from scapy.packet import Raw
|
from scapy.packet import Raw
|
||||||
from scapy.data import ETH_P_ALL
|
from scapy.data import ETH_P_ALL
|
||||||
from scapy.arch.consts import FREEBSD, OPENBSD, NETBSD
|
from scapy.consts import FREEBSD, OPENBSD, NETBSD
|
||||||
from scapy.utils import warning
|
from scapy.utils import warning
|
||||||
|
|
||||||
from scapy.arch.bpf.core import get_dev_bpf, attach_filter
|
from scapy.arch.bpf.core import get_dev_bpf, attach_filter
|
||||||
|
|
|
@ -11,7 +11,7 @@ import sys,os,struct,socket,time
|
||||||
from select import select
|
from select import select
|
||||||
from fcntl import ioctl
|
from fcntl import ioctl
|
||||||
|
|
||||||
from scapy.arch.consts import LOOPBACK_NAME
|
from scapy.consts import LOOPBACK_NAME
|
||||||
import scapy.utils
|
import scapy.utils
|
||||||
import scapy.utils6
|
import scapy.utils6
|
||||||
from scapy.packet import Packet, Padding
|
from scapy.packet import Packet, Padding
|
||||||
|
|
|
@ -16,7 +16,7 @@ import scapy.config
|
||||||
import scapy.utils
|
import scapy.utils
|
||||||
from scapy.utils6 import in6_getscope, construct_source_candidate_set
|
from scapy.utils6 import in6_getscope, construct_source_candidate_set
|
||||||
from scapy.utils6 import in6_isvalid, in6_ismlladdr, in6_ismnladdr
|
from scapy.utils6 import in6_isvalid, in6_ismlladdr, in6_ismnladdr
|
||||||
from scapy.arch.consts import FREEBSD, NETBSD, OPENBSD, SOLARIS, LOOPBACK_NAME
|
from scapy.consts import FREEBSD, NETBSD, OPENBSD, SOLARIS, LOOPBACK_NAME
|
||||||
from scapy.arch import get_if_addr
|
from scapy.arch import get_if_addr
|
||||||
from scapy.config import conf
|
from scapy.config import conf
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,8 @@ from scapy.config import conf,ConfClass
|
||||||
from scapy.error import Scapy_Exception,log_loading,log_runtime
|
from scapy.error import Scapy_Exception,log_loading,log_runtime
|
||||||
from scapy.utils import atol, itom, inet_aton, inet_ntoa, PcapReader
|
from scapy.utils import atol, itom, inet_aton, inet_ntoa, PcapReader
|
||||||
from scapy.base_classes import Gen, Net, SetGen
|
from scapy.base_classes import Gen, Net, SetGen
|
||||||
import scapy.plist as plist
|
|
||||||
from scapy.data import MTU, ETHER_BROADCAST, ETH_P_ARP
|
from scapy.data import MTU, ETHER_BROADCAST, ETH_P_ARP
|
||||||
from scapy.arch.consts import LOOPBACK_NAME
|
from scapy.consts import LOOPBACK_NAME
|
||||||
|
|
||||||
conf.use_pcap = False
|
conf.use_pcap = False
|
||||||
conf.use_dnet = False
|
conf.use_dnet = False
|
||||||
|
|
|
@ -15,7 +15,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from scapy.arch.consts import LOOPBACK_NAME
|
from scapy.consts import LOOPBACK_NAME
|
||||||
from scapy.config import conf,ConfClass
|
from scapy.config import conf,ConfClass
|
||||||
from scapy.base_classes import Gen, SetGen
|
from scapy.base_classes import Gen, SetGen
|
||||||
import scapy.plist as plist
|
import scapy.plist as plist
|
||||||
|
@ -168,8 +168,8 @@ def sndrcv(pks, pkt, timeout = 2, inter = 0, verbose=None, chainCC=0, retry=0, m
|
||||||
return plist.SndRcvList(ans),plist.PacketList(remain,"Unanswered")
|
return plist.SndRcvList(ans),plist.PacketList(remain,"Unanswered")
|
||||||
|
|
||||||
|
|
||||||
import scapy.sendrecv
|
import scapy.sendrecv as sendrecv
|
||||||
scapy.sendrecv.sndrcv = sndrcv
|
sendrecv.sndrcv = sndrcv
|
||||||
|
|
||||||
def sniff(count=0, store=1, offline=None, prn = None, lfilter=None, L2socket=None, timeout=None, *arg, **karg):
|
def sniff(count=0, store=1, offline=None, prn = None, lfilter=None, L2socket=None, timeout=None, *arg, **karg):
|
||||||
"""Sniff packets
|
"""Sniff packets
|
||||||
|
@ -249,7 +249,7 @@ L2socket: use the provided L2socket
|
||||||
return plist.PacketList(lst,"Sniffed")
|
return plist.PacketList(lst,"Sniffed")
|
||||||
|
|
||||||
import scapy.sendrecv
|
import scapy.sendrecv
|
||||||
scapy.sendrecv.sniff = sniff
|
sendrecv.sniff = sniff
|
||||||
|
|
||||||
# If wpcap.dll is not available
|
# If wpcap.dll is not available
|
||||||
if not (conf.use_winpcapy or conf.use_pcap or conf.use_dnet):
|
if not (conf.use_winpcapy or conf.use_pcap or conf.use_dnet):
|
||||||
|
|
|
@ -3,9 +3,34 @@
|
||||||
## Copyright (C) Philippe Biondi <phil@secdev.org>
|
## Copyright (C) Philippe Biondi <phil@secdev.org>
|
||||||
## This program is published under a GPLv2 license
|
## This program is published under a GPLv2 license
|
||||||
|
|
||||||
import os
|
import os, inspect
|
||||||
from sys import platform
|
from sys import platform
|
||||||
import platform as platform_lib
|
import platform as platform_lib
|
||||||
|
from scapy.error import *
|
||||||
|
|
||||||
|
try:
|
||||||
|
from matplotlib import get_backend as matplotlib_get_backend
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
MATPLOTLIB = 1
|
||||||
|
if "inline" in matplotlib_get_backend():
|
||||||
|
MATPLOTLIB_INLINED = 1
|
||||||
|
else:
|
||||||
|
MATPLOTLIB_INLINED = 0
|
||||||
|
MATPLOTLIB_DEFAULT_PLOT_KARGS = {"marker": "+"}
|
||||||
|
# RuntimeError to catch gtk "Cannot open display" error
|
||||||
|
except (ImportError, RuntimeError):
|
||||||
|
plt = None
|
||||||
|
MATPLOTLIB = 0
|
||||||
|
MATPLOTLIB_INLINED = 0
|
||||||
|
MATPLOTLIB_DEFAULT_PLOT_KARGS = dict()
|
||||||
|
log_loading.info("Can't import matplotlib. Won't be able to plot.")
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pyx
|
||||||
|
PYX=1
|
||||||
|
except ImportError:
|
||||||
|
log_loading.info("Can't import PyX. Won't be able to use psdump() or pdfdump().")
|
||||||
|
PYX=0
|
||||||
|
|
||||||
LINUX = platform.startswith("linux")
|
LINUX = platform.startswith("linux")
|
||||||
OPENBSD = platform.startswith("openbsd")
|
OPENBSD = platform.startswith("openbsd")
|
||||||
|
@ -31,3 +56,6 @@ else:
|
||||||
X86_64 = uname[4] == 'x86_64'
|
X86_64 = uname[4] == 'x86_64'
|
||||||
ARM_64 = uname[4] == 'aarch64'
|
ARM_64 = uname[4] == 'aarch64'
|
||||||
LOOPBACK_NAME = "lo" if LINUX else "lo0"
|
LOOPBACK_NAME = "lo" if LINUX else "lo0"
|
||||||
|
|
||||||
|
def parent_function():
|
||||||
|
return inspect.getouterframes(inspect.currentframe())
|
|
@ -18,7 +18,7 @@ from scapy.plist import SndRcvList
|
||||||
from scapy.fields import *
|
from scapy.fields import *
|
||||||
from scapy.sendrecv import srp, srp1, srpflood
|
from scapy.sendrecv import srp, srp1, srpflood
|
||||||
from scapy.arch import get_if_hwaddr
|
from scapy.arch import get_if_hwaddr
|
||||||
from scapy.arch.consts import LOOPBACK_NAME
|
from scapy.consts import LOOPBACK_NAME
|
||||||
from scapy.utils import inet_ntoa, inet_aton
|
from scapy.utils import inet_ntoa, inet_aton
|
||||||
if conf.route is None:
|
if conf.route is None:
|
||||||
# unused import, only to initialize conf.route
|
# unused import, only to initialize conf.route
|
||||||
|
|
|
@ -15,8 +15,7 @@ from scapy.config import conf
|
||||||
from scapy.base_classes import BasePacket,BasePacketList
|
from scapy.base_classes import BasePacket,BasePacketList
|
||||||
from scapy.utils import do_graph,hexdump,make_table,make_lined_table,make_tex_table,get_temp_file
|
from scapy.utils import do_graph,hexdump,make_table,make_lined_table,make_tex_table,get_temp_file
|
||||||
|
|
||||||
from scapy.arch import plt, MATPLOTLIB_INLINED, MATPLOTLIB_DEFAULT_PLOT_KARGS
|
from scapy.consts import plt, MATPLOTLIB_INLINED, MATPLOTLIB_DEFAULT_PLOT_KARGS
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
|
|
|
@ -8,7 +8,7 @@ Routing and handling of network interfaces.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
from scapy.arch.consts import LOOPBACK_NAME
|
from scapy.consts import LOOPBACK_NAME
|
||||||
from scapy.utils import atol,ltoa,itom
|
from scapy.utils import atol,ltoa,itom
|
||||||
from scapy.config import conf
|
from scapy.config import conf
|
||||||
from scapy.error import Scapy_Exception,warning
|
from scapy.error import Scapy_Exception,warning
|
||||||
|
|
|
@ -12,7 +12,7 @@ import cPickle,os,sys,time,subprocess
|
||||||
import itertools
|
import itertools
|
||||||
from select import select, error as select_error
|
from select import select, error as select_error
|
||||||
|
|
||||||
from scapy.arch.consts import DARWIN, FREEBSD, OPENBSD
|
from scapy.consts import DARWIN, FREEBSD, OPENBSD
|
||||||
from scapy.data import *
|
from scapy.data import *
|
||||||
from scapy.config import conf
|
from scapy.config import conf
|
||||||
from scapy.packet import Gen
|
from scapy.packet import Gen
|
||||||
|
|
|
@ -9,7 +9,7 @@ Unit testing infrastructure for Scapy
|
||||||
|
|
||||||
import sys,getopt,imp
|
import sys,getopt,imp
|
||||||
import bz2, base64, os.path, time, traceback, zlib, sha
|
import bz2, base64, os.path, time, traceback, zlib, sha
|
||||||
from scapy.arch.consts import WINDOWS
|
from scapy.consts import WINDOWS
|
||||||
|
|
||||||
|
|
||||||
#### Import tool ####
|
#### Import tool ####
|
||||||
|
|
Loading…
Reference in New Issue