使用Scapy来嗅探管理帧

huangapple go评论96阅读模式
英文:

Using Scapy to sniff beacon packets

问题

我正在尝试使用Scapy捕获Wi-Fi接入点的信标类型数据包,然后提取它们的MAC地址和RSSI。当我运行代码时,似乎没有发生任何事情。我做错了什么?我使用的过滤器不正确吗,还是其他原因?

from scapy.all import sniff
import os

interface = "wlp3s0"
interface_mon = "wlp3s0mon"

os.system("sudo -S airmon-ng check kill")
os.system(f"sudo airmon-ng start {interface}")
os.system("sudo iwconfig")

# 使用信标帧类型的过滤器捕获Wi-Fi数据包
packets = sniff(iface=interface_mon, filter="type mgt subtype beacon", count=10)
# 提取每个接入点的MAC地址和信号强度(RSSI)
access_points = []
for pkt in packets:
    mac = pkt.addr3
    rssi = -(256-ord(pkt.notdecoded[-2:-1]))
    access_points.append({'mac': mac, 'rssi': rssi})

print(access_points)

请注意,我已将代码中的HTML实体编码还原为正常的引号字符。希望这有助于解决您的问题。

英文:

I'm trying to use Scapy to capture beacon type packets from wi-fi access points and then extract their mac address and rssi. When i run the code nothing seems to happen. What am i doing wrong? Is the filter i'm using not the right one or is it something else?

from scapy.all import sniff
import os

interface = "wlp3s0"
interface_mon = "wlp3s0mon"

os.system(f"sudo -S airmon-ng check kill")
os.system(f"sudo airmon-ng start {interface} ")
os.system(f"sudo iwconfig")

# Capture Wi-Fi packets with a filter for beacon frames
packets = sniff(iface=interface_mon, filter="type mgt subtype beacon", count=10)
# Extract the MAC address and signal strength (RSSI) of each access point
access_points = []
for pkt in packets:
    mac = pkt.addr3
    rssi = -(256-ord(pkt.notdecoded[-2:-1]))
    access_points.append({'mac': mac, 'rssi': rssi})

print(access_points)

答案1

得分: 1

问题是由于我的当前适配器驱动程序不支持监控模式而引起的。所以代码是正确的,但适配器没有捕获任何内容。将驱动程序回滚到较早版本解决了这个问题。

英文:

The problem was caused by my current adapter driver not supporting monitor mode. So the code was working right but the adapter wasn't capturing anything. Rolling back the driver to an earlier version fixed it.

huangapple
  • 本文由 发表于 2023年3月3日 23:26:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75628972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定