Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在scapy中获得http支持_Python_Http_Scapy_Packet Sniffers - Fatal编程技术网

Python 如何在scapy中获得http支持

Python 如何在scapy中获得http支持,python,http,scapy,packet-sniffers,Python,Http,Scapy,Packet Sniffers,我正在使用scapy在python中构建一个数据包嗅探器,现在,我想过滤我正在接收的http数据包并从中提取url(主机+路径),但我的程序崩溃了,消息是:文件“packet_sniffer.py”,第4行,in 从scapy.layers.http导入* ImportError:没有名为http的模块 当输入scapy layers http import时,我可以自动完成http部分,因此它似乎可以识别它,但在运行时会崩溃 我在代码部分尝试了其他语法,比如使用“scapy.http.HTTP

我正在使用scapy在python中构建一个数据包嗅探器,现在,我想过滤我正在接收的http数据包并从中提取url(主机+路径),但我的程序崩溃了,消息是:文件“packet_sniffer.py”,第4行,in 从scapy.layers.http导入* ImportError:没有名为http的模块

当输入scapy layers http import时,我可以自动完成http部分,因此它似乎可以识别它,但在运行时会崩溃

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

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


**注意,我正在使用scapy 2.4.3

请确保您正在使用scapy 2.4.3

使用库
scapy_http
如何,方法是将scapy.layers.http导入*中的
替换为scapy_http导入*

就像

我使用的是2.4.3版本,这听起来在技术上是不可能的。Scapy 2.4.3包含一个模块
Scapy.layers.http
。确保
scapy.\uuuuu版本\uuuuu
为2.4.3。如果您有多个Python版本的环境,请确保使用正确的管理器(例如pip3…)安装了Scapy。否。Scapy http已过时:
#!/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)