scapy使用過程當中遇到的奇葩事

主要是執行下面的命令時遇到兩個報錯:python

from scapy.all import *

1."IndexError: list index out of range" 輸入圖片說明 這個問題去google,查到說是由於安裝cisco的緣由,須要修改pythonhome\Lib\site-packages\scapy\arch\windows目錄下"init.py"(注意,init先後分別有兩個下劃線,不知爲什麼不能顯示)文件的_exec_query_ps函數,修改內容以下:git

def _exec_query_ps(cmd, fields):
    """Execute a PowerShell query"""
    ps = sp.Popen([conf.prog.powershell] + cmd +
                  ['|', 'select %s' % ', '.join(fields), '|', 'fl'],
                  stdout=sp.PIPE,
                  universal_newlines=True)
    l=[]
    for line in ps.stdout:
        if not line.strip(): #skip empty lines
            continue
        fv=line.split(':',1)
        if len(fv) == 1:
            l[-1] += fv[0].strip()
            continue
        else:
            l.append(fv[1].strip())

        #l.append(line.split(':', 1)[1].strip())
        if len(l) == len(fields):
            yield l
            l=[]

修改第一個問題後,再次執行"from scapy.all import *",報錯:ImportError:cannt import name read_routesgithub

輸入圖片說明

出現這個問題的緣由後來從一個羣友處得知,是由於我安裝的python是32-bit,計算機是64-bit.後來將python更換爲64-bit,再執行"from scapy.all import *"就沒有再出現什麼奇葩的問題.shell

因此,你們在安裝python時,盡肯能的安裝和系統位數同樣的版本.windows

附註: 第一個報錯解決方法相關連接: https://github.com/secdev/scapy/issues/400app

相關文章
相關標籤/搜索