【发布时间】:2015-05-19 17:12:39
【问题描述】:
所以我得到了当前的原始套接字:
from socket import socket, AF_INET, SOCK_RAW, SOCK_STREAM
from struct import unpack
from binascii import hexlify
rawsocket = socket(AF_INET, SOCK_RAW)
rawsocket.bind(("192.168.2.4", 8000))
while True:
request = rawsocket.recvfrom(2048)
#this part is for the sake of the question
if len(request) is not 0:
print(request)
request = ""
如您所见,它在端口8000 上等待192.168.2.4 上的传入数据包。我可以成功到达这个港口。我查看了https://docs.python.org/3.4/library/struct.html 以了解我必须如何理解第一层(wlan),但我不知道该怎么做。
我试过谷歌搜索但没有成功,如果你知道如何解压这一层,你能告诉我你是怎么知道你这样解压的吗?
我知道我必须这样做
header = request[0][0:x] #But how for must x go for the wlan layer?
hd = unpack("y", header) #But what fmt must y be? how do I know?
编辑:
我知道y 必须以! 开头,我也知道x 必须是该层的总字节数:(我的方向是否正确)
【问题讨论】:
-
基于wildpackets.com/resources/compendium/wireless_lan/wlan_packets 看起来你需要继续阅读直到你得到终端字符(不确定那是什么但它在校验和之后出现)..你不能指望一个固定的数字消息的字节数......但你可以看到它有一个 2byte FC、一个 2byte 持续时间、几个 6 byte 地址和一些序列控制......你可能只需要反复试验......
-
你的无线网卡在什么模式下?
标签: python sockets struct layer unpack