繁体   English   中英

如何在 scapy 中获得 http 支持

[英]How to get http support in scapy

I am building a packet sniffer in python using scapy, now, I want to filter the http packets I am receiving and extract the url from them(Host + Path) but my program crashes with message: File "packet_sniffer.py", line 4 ,从 scapy.layers.http 导入 * ImportError: No module named http

当键入 scapy 层 http 导入时,我可以自动完成 http 部分,所以它似乎可以识别它,但是在运行时它会崩溃。

我在我的代码部分尝试了其他语法,例如使用“scapy.http.HTTPRequest”“scapy.layers.http.HTTPRequest”

#!/usr/bin/env python

import scapy.all as scapy
from scapy.layers.http import *




def sniff(interface):
scapy.sniff(iface=interface,
            store=False,
            prn=process_sniffed_packet,
            lfilter=lambda p: "POST" in str(p),
            filter="tcp port 80")


def process_sniffed_packet(packet):
    url = packet[scapy.layers.http.HTTPRequest].Host + packet[scapy.layers.http.HTTPRequest].Path
    print(url)

我的模块导入或代码有问题吗?

** 注意,我使用的是 scapy 2.4.3

确保您使用的是 Scapy 2.4.3

如何使用库scapy_http通过替换from scapy.layers.http import *from scapy_http import *这样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM