首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在osx上安装Scapy失败,出现dnet导入错误

在osx上安装Scapy失败,出现dnet导入错误
EN

Stack Overflow用户
提问于 2014-10-07 13:24:01
回答 3查看 17K关注 0票数 19

安装Scapy时遇到问题,它是必需的依赖项。我花了一些时间在谷歌上寻找解决方案,但所有的“解决方案”似乎都会影响旧版本的Python,或者根本不起作用。

脚本:

代码语言:javascript
复制
#!/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路径。

代码语言:javascript
复制
which python
/usr/bin/python

当执行脚本时,我得到以下错误:

代码语言:javascript
复制
./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)

代码语言:javascript
复制
` ~/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 

使用新标志进行编译的结果

代码语言:javascript
复制
 ~/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   
EN

回答 3

Stack Overflow用户

发布于 2015-02-08 01:23:45

上面提到的所有问题似乎都得到了解决。我在运行OS X Yosemite。通过以下三个命令,我得到了一个可用的替罪羊。

代码语言:javascript
复制
brew install --with-python libdnet
pip install pcapy
pip install scapy
票数 16
EN

Stack Overflow用户

发布于 2015-01-19 06:08:16

我运行的是OSX 10.5.9 --我花了很长时间尝试让它正常工作--在安装了dnet/pcap库之后,我也收到了"OSError:Device not configured“的提示。已尝试将unix.py中的第34行替换为

"netstat -rn | grep -v vboxnet"

仍然得到相同的错误。但是,当我在if块的"else“部分更改了第37行时:

代码语言:javascript
复制
def read_routes():
    if scapy.arch.SOLARIS:
        f=os.popen("netstat -rvn") # -f inet
    elif scapy.arch.FREEBSD:
        f=os.popen("netstat -rnW") # -W to handle long interface names
    else:
        # f=os.popen("netstat -rn") # -f inet
        f=os.popen("netstat -rn | grep -v vboxnet") # -f inet

就像一种护身符!

票数 2
EN

Stack Overflow用户

发布于 2016-11-12 06:04:26

在OSX El Capitan中,对我起作用的是强制pip使用sudo:sudo pip install --user pcapy -I重新安装pcapy。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26229057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档