3th*_*1ll 19 python macos installation scapy importerror
无法安装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'
Run Code Online (Sandbox Code Playgroud)
Python版本是2.7.5并验证了Python的路径.
which python
/usr/bin/python
Run Code Online (Sandbox Code Playgroud)
执行脚本时,我收到以下错误:
./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
Run Code Online (Sandbox Code Playgroud)
我可以使用Scapy和Python交互式解释器,并且import scapy在Python解释器中运行不会产生任何错误.当脚本最初运行时,pcapy模块丢失,但我安装了然后问题切换到dnet,我无法找到解决方案.
类似的帖子,似乎描述了同样的问题,但解决方法没有效果.任何人都可以对这个问题有所了解吗?
用于安装pcapy和libdnet的命令:
libdnet-1.11.tar.gz(01-19-2005)
` ~/Downloads/libdnet-1.11 ?
chmod a+x configure
~/Downloads/libdnet-1.11 ?
./configure && make`
Run Code Online (Sandbox Code Playgroud)
退出成功
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 ?
Run Code Online (Sandbox Code Playgroud)
Yoe*_*oel 16
编辑 - 下面的答案说明所有提到的问题都已修复,并提供了一种更简单的安装方法.然而,它的评论表明虽然它似乎适用于OS X 10.10 Yosemite和OS X 10.11 El Capitan,但它可能会因某些其他版本而失败.
您尚未完成安装$ pip install scapy及其Python包装器,如$ pip install --pre scapy[basic]安装指南中所述:
$ brew update # update Homebrew
$ brew install libpcap # install libpcap
Run Code Online (Sandbox Code Playgroud)
如果您的系统是64位,请改用以下编译命令:
$ sudo port -d selfupdate # update MacPorts
$ sudo port install libpcap # install libpcap
Run Code Online (Sandbox Code Playgroud)
此外,请确认您已安装正确的版本,即1.12而不是1.11.
如果失败,那么尝试通过安装$ pip install --pre scapy[complete]和使用它的from scapy.config import conf; conf.use_pcap = True文件,描述在这里:
$ brew install libdnet --with-python
$ pip install pcapy
$ pip install scapy
Run Code Online (Sandbox Code Playgroud)
该链接还建议更改from scapy.config import conf; conf.use_pcap = True(修复site-packages)中的一些代码.
改变第34行:
$ mkdir -p /Users/<USERNAME>/Library/Python/2.7/lib/python/site-packages
$ echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/<USERNAME>/Library/Python/2.7/lib/python/site-packages/homebrew.pth
Run Code Online (Sandbox Code Playgroud)
至:
$ wget https://github.com/dugsong/libdnet/archive/libdnet-1.12.tar.gz
$ tar xfz libdnet-1.12.tgz
$ ./configure
$ make
$ sudo make install
$ cd python
$ python2.5 setup.py install
Run Code Online (Sandbox Code Playgroud)
如下:
$ CFLAGS='-arch i386 -arch x86_64' ./configure
$ archargs='-arch i386 -arch x86_64' make
Run Code Online (Sandbox Code Playgroud)
如果仍然出现错误sys.path,则尝试对该dnet.so子句的其他分支(特别是其/Library/Python/2.7/site-packages/scapy/arch/unix.py分支)执行类似的更改,如本答案中所述.
Tim*_* Wu 16
上面提到的所有问题似乎都是固定的 我正在运行OS X Yosemite.我通过以下三个命令得到了一个工作scapy.
brew install --with-python libdnet
pip install pcapy
pip install scapy
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16438 次 |
| 最近记录: |