2014-10-07 100 views
18

在安裝Scapy時遇到問題,它需要依賴項。我花了一些時間搜索解決方案,但所有'解決方案'似乎都會影響舊版本的Python,或者根本不起作用。scapy安裝在dx導入錯誤的osx上失敗

腳本:

#!/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(2005年1月19日)

` ~/Downloads/libdnet-1.11  
chmod a+x configure 
~/Downloads/libdnet-1.11  
./configure && make` 

退出成功

Pcapy:最新穩定版(0.10 0.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  
+1

你如何安裝'scapy'和'pcapy'?你使用過哪些命令?是否有任何錯誤報告?你有沒有安裝['libdnet'](http://libdnet.sourceforge.net)? – Yoel 2014-10-07 17:06:19

+0

添加到原始帖子。所有退出成功,腳本在刷新終端中重新運行,但出現相同錯誤 – 2014-10-07 23:53:06

+0

您有什麼操作系統? – Yoel 2014-10-07 23:59:22

回答

14

編輯編譯 - This answer below指出,所有提到的問題是固定的,並提供了一個更簡單的安裝方法。然而,其評論表明,雖然它似乎在OS X 10.10優勝美地OS X 10.11埃爾卡皮坦,它可能會失敗的某些其他版本。


您尚未完成的libdnet安裝和Python包裝,如Scapy's installation guide說:

$ wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz 
$ tar xfz libdnet-1.12.tgz 
$ ./configure 
$ make 
$ sudo make install 
$ cd python 
$ python2.5 setup.py install 

如果你的系統是64位的,使用這些編輯命令來代替:

$ CFLAGS='-arch i386 -arch x86_64' ./configure 
$ archargs='-arch i386 -arch x86_64' make 

此外,請確認您已安裝正確版本,即1.12而不是1.11。

如果失敗,那麼嘗試通過macports安裝和使用它的dnet.so文件,描述here

$ port selfupdate 
$ port upgrade outdated 
$ port install py27-libdnet 
$ port install libdnet 
$ cp /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dnet.so /Library/Python/2.7/site-packages 

該鏈接還建議/Library/Python/2.7/site-packages/scapy/arch/unix.py改變一些代碼(修正OSError: Device not configured)。

更改行34:

f=os.popen("netstat -rn") # -f inet 

到:

f=os.popen("netstat -rn | grep -v vboxnet") # -f inet 

如下:

def read_routes(): 
    if scapy.arch.SOLARIS: 
#  f=os.popen("netstat -rvn") # -f inet 
     f=os.popen("netstat -rn | grep -v vboxnet") # -f inet 

如果仍然出現錯誤OSError: Device not configured,然後嘗試進行到類似的變化if條款的其他分支(具體來說,就是其else分支),如this answer中所述。

+0

是的,我也跑了,再次,退出罰款,但同樣的錯誤導入dnet – 2014-10-08 00:54:16

+0

這似乎是錯誤的一部分。 '從pcapdnet進口* 文件 「/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py」,線路160,在 進口DNET 導入錯誤:沒有模塊名爲dnet' – 2014-10-08 01:07:32

+0

獲得一個配置錯誤,我已將輸出添加到原始帖子。 – 2014-10-08 01:31:20

2

我正在運行OSX 10.5.9 - 花費永遠試圖讓scapy工作 - 在安裝dnet/pcap庫之後我也得到了「OSError:Device not configured」。試圖與

"netstat -rn | grep -v vboxnet"

仍然得到了同樣的錯誤替換unix.py線34。但是,當我改變行37,而不是在if的其他部分:

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 

工程就像一個魅力!

16

上述所有問題似乎都是固定的。我正在運行OS X Yosemite。我通過以下三個命令得到了一個有效的scapy。

brew install --with-python libdnet 
pip install pcapy 
pip install scapy 
+2

但是缺少dnet「ImportError:沒有名爲dnet的模塊」 – PiyusG 2015-04-25 02:19:09

+0

在這裏相同。你是如何擺脫缺少的dnet錯誤的? – 2015-08-27 21:30:42

+1

儘管如此,仍然是dnet錯誤。這個答案應該被拒絕。 – jeffehobbs 2016-05-31 22:29:10

2

(這是Tim Wu的答案評論,但我錯過了聲譽這樣做)

記住做什麼釀造實際上是在告訴你:

==> Caveats
Python modules have been installed and Homebrew's site-packages is not in your Python sys.path, so you will not be able to import the modules this formula installed.
If you plan to develop with these modules, please run: [...]

mkdir -p /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages 
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages/homebrew.pth 

所以,只需重新運行brew命令並執行它告訴你在那裏使用所有已安裝的brew python軟件包的兩行。

+0

注意:如果您複製粘貼上述腳本,請記得編輯「YourUsernameHere」! – 2016-10-31 08:48:45

0

在OSX埃爾卡皮坦,什麼工作對我來說是迫使PIP使用sudo重新安裝pcapy: sudo pip install --user pcapy -I

相關問題