本文介绍了Scapy sniff() 不接受 iface 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全新安装 Python2.7.14 和 scapy(版本 git-archive.dev254ab6d5a)后,我无法将 LAN 卡定义为接口.只要 iface=None 嗅探功能就可以正常工作.如果我将 iface 分配给一个字符串,我会收到以下错误.对于这个错误,我没有在 google:/上找到任何帖子.

代码:

#从以太网 Api 导入所有必要的 scapy 功能从 Lib.IHR_EthApi 导入 *从 Lib.IHR_GeneralApi 导入 GeneralApi 作为 SYS从 scapy.all 导入 *FullTrafficList = []#show_interfaces()scapy.all.sniff(lfilter=None, iface="Realtek PCIe GBE 系列控制器", store=True, prn = lambda x: FullTrafficList.append(x), count=10, timeout= None)SYS.IHR_print(str(FullTrafficList))

错误描述:

>回溯(最近一次通话):文件>c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\Test.py",第 8 行,>在<模块>>scapy.all.sniff(lfilter=None, iface="Realtek PCIe GBE 系列控制器", store=True, prn = lambda x: FullTrafficList.append(x),>计数=10,超时=无)文件>C:\Python27\Lib\site-packages\scapy\sendrecv.py",第 708 行,在嗅探中>*arg, **karg)] = iface 文件C:\Python27\Lib\site-packages\scapy\arch\pcapdnet.py",第 198 行,在>__在里面__>self.ins = open_pcap(iface, 1600, self.promisc, 100, monitor=monitor) 文件>C:\Python27\Lib\site-packages\scapy\arch\windows\__init__.py",行>第856话>如果 iface.ismonitor(): AttributeError: 'str' 对象没有属性 'ismonitor'
解决方案

我遇到了同样的问题好几个小时了.这是我为解决它所做的.

确保您拥有最新版本的 scapy 和最新版本的 npcap.安装 npcap 时,单击选项以打开监视模式.我也在 scapy 文档网站上找到了这个

Winpcap/Npcap 冲突

由于Winpcap越来越老,建议改用Npcap.Npcap 是 Nmap 项目的一部分.

如果您收到消息Winpcap is installed over Npcap.",这意味着您已经安装了 winpcap 和 npcap 版本,这是不推荐的.您可以从您的程序文件中卸载 winpcap,然后您需要删除:

C:/Windows/System32/wpcap.dllC:/Windows/System32/Packet.dll

如果您使用的是 x64 机器:

 C:/Windows/SysWOW64/wpcap.dllC:/Windows/SysWOW64/Packet.dll

改为使用 npcap.Winpcap 卸载程序不会删除这些文件.

在我这样做之后,我使用

列出了接口

 show_interfaces()iface = raw_input("进入要嗅探的界面:")

将界面复制粘贴到输入中

After a new installation of Python2.7.14 and scapy(Version git-archive.dev254ab6d5a) i cant define my LAN-card as interface. As long iface=None the sniff function works fine. If i assign iface to a string, i get the following Error. For this Error i didn't found any posts on google:/.

Code:

#Import all necessary scapy functionality from ethernet Api
from Lib.IHR_EthApi import *
from Lib.IHR_GeneralApi import GeneralApi as SYS
from scapy.all import *

FullTrafficList = []
#show_interfaces()
scapy.all.sniff(lfilter=None, iface="Realtek PCIe GBE Family Controller", store=True, prn = lambda x: FullTrafficList.append(x), count=10, timeout= None)
SYS.IHR_print(str(FullTrafficList))

Error describtion:

> Traceback (most recent call last):   File
> "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\Test.py", line 8,
> in <module>
>     scapy.all.sniff(lfilter=None, iface="Realtek PCIe GBE Family Controller", store=True, prn = lambda x: FullTrafficList.append(x),
> count=10, timeout= None)   File
> "C:\Python27\Lib\site-packages\scapy\sendrecv.py", line 708, in sniff
>     *arg, **karg)] = iface   File "C:\Python27\Lib\site-packages\scapy\arch\pcapdnet.py", line 198, in
> __init__
>     self.ins = open_pcap(iface, 1600, self.promisc, 100, monitor=monitor)   File
> "C:\Python27\Lib\site-packages\scapy\arch\windows\__init__.py", line
> 856, in open_pcap
>     if iface.ismonitor(): AttributeError: 'str' object has no attribute 'ismonitor'
解决方案

I had this same issue for hours. Here's what I did to solve it.

Be sure you have the latest version of scapy and the latest version of npcap. When you install npcap click the option to turn monitor mode on. I also found this on the scapy documentation site

C:/Windows/System32/wpcap.dll
C:/Windows/System32/Packet.dll
    C:/Windows/SysWOW64/wpcap.dll
    C:/Windows/SysWOW64/Packet.dll

after I did that I listed the interfaces using

    show_interfaces()
    iface = raw_input("Enter the interface to sniff on: ")

copy and paste the interface into the input

这篇关于Scapy sniff() 不接受 iface 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 05:14