使用Scapy的数据包嗅探器

时间:2019-01-14 06:05:02

标签: python scapy pcap packet-capture packet-sniffers

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

enter image description here->重要

所以这是代码

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()

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

谢谢。

1 个答案:

答案 0 :(得分:0)

./home/...是有效路径。请改用/home/...

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

相关问题