首页 > 解决方案 > 使用 Scapy 的数据包嗅探器

问题描述

我已经在 python 中使用 scapy 编写了嗅探数据包的代码。我遇到了一些让我感到困惑的问题,如下图所示。

在此处输入图像描述-> 重要

所以这是代码

import subprocess
import time
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
logging.getLogger("scapy.loading").setLevel(logging.ERROR)
logging.getLogger("scapy.interactive").setLevel(logging.ERROR)

try:
    from scapy.all import *
except ImportError:
    sys.exit()

interface = 'wlp10s0'
subprocess.call(["ifconfig",interface,"promisc"],stdout=None,stderr=None,shell=False)
print 'Interface has been set to Promiscous mode'

totalpackets=0
sniffingtime=10
protocols=0
infinite=1

def timenow():
    currenttime=time.strftime("%m%d%y-%H%M%S")
    return currenttime

def export():
    p = sniff(iface='wlp10s0',timeout=sniffingtime,count=0)
    wrpcap('./home/Desktop/' + timenow() + '.pcap',p);

while infinite==1 :
    export()

我希望有人可以帮助我解决此代码。

谢谢你。

标签: pythonscapypcappacket-capturepacket-sniffers

解决方案


./home/...是一个有效的路径。改为使用/home/...

它清楚地显示“OSerror:没有这样的文件或目录”。您可能想查找这些错误 ;-)


推荐阅读