麻烦安装Scapy,它是必需的依赖。我已经花了一些时间Googling解决方案,但所有的“解决方案”似乎影响旧版本的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
from scapy.all import *
File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in
from arch import *
File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line 75, in
from bsd import *
File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, in
from unix import *
File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20, in
from pcapdnet import *
File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line 160, in
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日
〜/下载/ pcapy-0.10.8
sudo python setup.py安装
密码:
运行安装
运行构建
运行build_ext
运行build_scripts
运行install_lib
运行install_scripts
将/usr/local/bin/96pings.pcap的模式更改为777
将/usr/local/bin/pcapytests.py更改为777模式
运行install_data
运行install_egg_info
删除/Library/Python/2.7/site-packages/pcapy-0.10.8-py2.7.egg-info
写/Library/Python/2.7/site-packages/pcapy-0.10.8-py2.7.egg-info
〜/下载/ 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