Python套接字无线扫描输出

Python套接字无线扫描输出,python,sockets,wireless,Python,Sockets,Wireless,我这里有这个代码: import socket raw = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003)) raw.bind(("mon0", 0x0003)) ap_list = set() out = open("out.cap", 'w') while True: pkt = raw.recvfrom(2048)[0] if pkt[36:42] not in ap_lis

我这里有这个代码:

import socket
raw = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
raw.bind(("mon0", 0x0003))
ap_list = set()
out = open("out.cap", 'w')
while True:
    pkt = raw.recvfrom(2048)[0]
        if pkt[36:42] not in ap_list:
            ap_list.add(pkt[36:42])
            print (pkt)
            out.writelines(str(pkt))
但是输出对我来说有点奇怪。如何使它具有可读性

输出示例:

b'\x00!c\xf60\xbe\x807s\xa8\xe5@\x08\x00E\x00\x004\xea\xec@\x00$\x06\xd2\xcck\x15mA\xc0\xa8\x00\x0c\x00P\x90\xee\x9dx\xd9E=\xfd;[\x80\x10\x00no\xc0\x00\x00\x01\x01\x08\n)\xa0w\x10\x00\xd6J\xa8'
更新: 用这个

decoded = pkt.decode("ISO-8859-1")
我已经设法做到了我需要的,但是wireshark不能很好地读取我的输出文件,我还需要从输出中删除无用的数据

要帮忙吗

这是新代码:

import socket
import sys

raw = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
raw.bind((sys.argv[1], 0x0003))
ap_list = set()
out = open("out.cap", 'w')
while True:
    pkt = raw.recvfrom(1024)[0]
    if pkt[36:42] not in ap_list:
        ap_list.add(pkt[36:42])
        decoded = pkt.decode("ISO-8859-1")
        print(str(pkt[0:20]).split("'")[1])
        out.writelines(str(decoded) + "\n")

在Wireshark中,您应该能够看到正在使用哪些协议。然后可以解析它们,例如使用
scapy
包。
–John Zwinck

现在的输出是什么样子的?打印在终端上的pkt看起来是:;ÛÄ6ÛÄz{y[…]并在文件中输出,然后在sublime中打开,看起来像:c398 04c3 8b79 5620 00c2 81c3 8436 c290[…]你认为那是什么协议?为什么你希望它是人类可读的?我知道它不是人类可读的,我使用wireshark读取它,但有时他不想加载输出…我在网上看到一些代码,人们设法提取一些信息,如MAC地址或类似的东西,我想知道是否可以做sa在wireshark中,我看到了一些关于访问过的网页的信息,但是如何提取这些信息呢?谢谢,使用scapy更容易,只需六行代码,就可以了