Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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获取有关第2层连接的信息_Python_Scapy_Pcap_Wifi - Fatal编程技术网

Python 使用scapy获取有关第2层连接的信息

Python 使用scapy获取有关第2层连接的信息,python,scapy,pcap,wifi,Python,Scapy,Pcap,Wifi,我想使用scapy从pcap文件中获取关于协议802.11中mac地址“对话”的信息。我做了一些与使用tcp连接类似的工作: l = self.pcap[int(arg)] ipsrc = l.getlayer("IP").src ipdst = l.getlayer("IP").dst portsrc = l.getlayer("TCP").sport portdst = l.getlayer("TCP").dport pkt = []

我想使用scapy从pcap文件中获取关于协议802.11中mac地址“对话”的信息。我做了一些与使用tcp连接类似的工作:

    l = self.pcap[int(arg)]
    ipsrc = l.getlayer("IP").src
    ipdst = l.getlayer("IP").dst
    portsrc = l.getlayer("TCP").sport
    portdst = l.getlayer("TCP").dport

    pkt = []
    pkt.append([])
    for i,p in enumerate(self.pcap):
        if p.haslayer('TCP'):
            if p[IP].src == ipsrc and p[IP].dst == ipdst and p[TCP].sport == portsrc and p[TCP].dport == portdst:
                pkt.append([i, p])
            if p[IP].src == ipdst and p[IP].dst == ipsrc and p[TCP].sport == portdst and p[TCP].dport == portsrc:
                pkt.append([i, p])
其中,
arg
是表示数据包ID的数字,
self.pcap
是使用命令
rdpcap
打开的pcap文件


除了mac地址和802.11协议之外,有人知道如何实现与上述功能相同的功能吗?谢谢。

请参阅从802.11 mac头获取mac地址的示例:

from scapy.all import *

pcap = rdpcap('test_wifi.pcap')
for pkt in pcap:
    if pkt.haslayer(Dot11):
        print "Addr1 = %s, Addr2 = %s, Addr3 = %s, Addr4 = %s" %(pkt.addr1, pkt.addr2, pkt.addr3, pkt.addr4)

我将无线网卡设置为监控模式,并将捕获的数据包保存到“test_wifi.pcap”文件中以测试此代码。

您想获取有关以太网封装到802.11 mac头或仅802.11 mac头的信息吗?@Dmitry mac头