【发布时间】:2014-12-01 11:16:39
【问题描述】:
安装 Scapy 时遇到问题,它需要依赖项。我花了一些时间在谷歌上搜索解决方案,但所有“解决方案”似乎都会影响旧版本的 Python,或者根本不起作用。
脚本:
#!/usr/bin/python
import threading
import Queue
import time
from scapy.all import *
class WorkerThread(threading.Thread) :
def __init__(self, queue, tid) :
threading.Thread.__init__(self)
self.queue = queue
self.tid = tid
print 'Worker: %d' %self.tid
def run(self) :
total_ports = 0
while True :
port = 0
try :
port = self.queue.get(timeout=1)
except Queue.Empty :
print 'Worker %d exiting. %d ports scanned' %(self.tid, total_ports)
return
#Scanning begins
ip = sys.argv[1]
response = sr1(IP(dst=ip)/TCP(dport=port, flags='S'), verbose=False, timeout=.2)
if response :
if response[TCP].flags == 18 :
print 'ThreadID: %d: Got port no. %d status: OPEN' %(self.tid, port)
self.queue.task_done()
total_ports += 1
queue = Queue.Queue()
threads = []
for i in range(1, 10) :
print 'Creating WorkerThread : %d' %i
worker = WorkerThread(queue, i)
worker.setDaemon(True)
worker.start()
threads.append(worker)
print 'WorkerThread %d created' %i
for j in range(1, 100) :
queue.put(j)
queue.join()
for item in threads :
item.join()
print 'Scanning complete'
Python 版本为 2.7.5,Python 路径已验证。
which python
/usr/bin/python
执行脚本时出现以下错误:
./multi-threaded-scanner.py
Traceback (most recent call last):
File "./multi-threaded-scanner.py", line 6, in <module>
from scapy.all import *
File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in <module>
from arch import *
File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line 75, in <module>
from bsd import *
File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, in <module>
from unix import *
File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20, in <module>
from pcapdnet import *
File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line 160, in <module>
import dnet
ImportError: No module named dnet
我可以同时使用 Scapy 和 Python 交互式解释器,并且在 Python 解释器中运行 import scapy 不会产生任何错误。
当脚本最初运行时,pcapy 模块丢失了,但是我安装了它
然后问题切换到 dnet,我找不到解决方案。
A similar post,似乎描述了同样的问题,但变通方法无效。
任何人都可以进一步阐明这个问题吗?
用于安装 pcapy 和 libdnet 的命令:
libdnet-1.11.tar.gz (01-19-2005)
` ~/Downloads/libdnet-1.11
chmod a+x configure
~/Downloads/libdnet-1.11
./configure && make`
成功退出
Pcapy:最新稳定版本 (0.10.8),于 2010 年 8 月 26 日更新
~/Downloads/pcapy-0.10.8
sudo python setup.py install
Password:
running install
running build
running build_ext
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/local/bin/96pings.pcap to 777
changing mode of /usr/local/bin/pcapytests.py to 777
running install_data
running install_egg_info
Removing /Library/Python/2.7/site-packages/pcapy-0.10.8-py2.7.egg-info
Writing /Library/Python/2.7/site-packages/pcapy-0.10.8-py2.7.egg-info
~/Downloads/pcapy-0.10.8
使用新标志编译的结果
~/Downloads/libdnet-1.12
sudo CFLAGS='-arch i386 -arch x86_64' ./configure --prefix=/usr and archargs='-arch i386 -arch x86_64' make
configure: WARNING: you should use --build, --host, --target
configure: WARNING: you should use --build, --host, --target
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
/Users/richardcurteis/Downloads/libdnet-1.12/config/missing: Unknown `--is-lightweight' option
Try `/Users/richardcurteis/Downloads/libdnet-1.12/config/missing --help' for more information
configure: WARNING: 'missing' script is too old or missing
checking for a thread-safe mkdir -p... config/install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... Invalid configuration `and': machine `and' not recognized
configure: error: /bin/sh config/config.sub and failed
~/Downloads/libdnet-1.12
【问题讨论】:
-
你是如何安装
scapy和pcapy的?你用过哪些命令?是否报告了任何错误?你安装libdnet了吗? -
添加到原始帖子中。全部成功退出,脚本在刷新的终端中重新运行,但出现相同的错误
-
你有什么
OS? -
OSX Mavericks
System Version: OS X 10.9.5 (13F34) Kernel Version: Darwin 13.4.0 Boot Volume: Macintosh HD Boot Mode: Normal
标签: python macos installation importerror scapy