gpt4 book ai didi

python - 比特流 udp 跟踪器响应

转载 作者:太空宇宙 更新时间:2023-11-03 11:09:39 26 4
gpt4 key购买 nike

我怀疑 udp 公告响应是如何按照 bep udp 协议(protocol)规范中的建议处理的

import socket,struct
clisocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
connection_id=0x41727101980
transaction_id = 12345

# responses Tracker : Specification UDP [ User Datagaram Protocol ]
info_hash = "%1D%D4%D1%EDQn%DB%5CL%83%90%1B%2B%F8%83%A2%19%C0%7C%98"
peer_id = "-UT1234-m%09%B2%D5%99%FA%1Fj%88%AC%0D%A7"
action =1 # announce
downloaded = 0
left = 0
uploaded = 0
event =0
ip = 0
key = 0
num_want = -1
port = 9999

announce_pack = struct.pack(">QLL20s20sQQQLLLLH",connection_id,action,transaction_id,info_hash,peer_id,down loaded,left,uploaded,event,ip,key,num_want,port)
clisocket.sendto(announce_pack, ("tracker.ccc.de", 80))
res = clisocket.recv(1024)
action=struct.unpack(">HLLLLQQQ20s20sLLQ",res)

但是我得到以下错误

DeprecationWarning: struct integer overflow masking is deprecated announce_pack=struct.pack(">QLL20s20sQQQLLLLH",connection_id,action,transaction_id,info_hash,peer_id,downloaded,left,uploaded,event,ip,key,num_want,port)
Traceback (most recent call last):
action=struct.unpack(">HLLLLQQQ20s20sLLQ",res)
struct.error: unpack requires a string argument of length 98

最佳答案

看起来您向结构传递的字符串过大,可能是因为您收到了多个数据包。尝试

action=struct.unpack(">HLLLLQQQ20s20sLLQ",res[:98])

此外,您似乎没有正确解析公告响应。参见 here用于 UDP 跟踪器数据包的格式。

关于python - 比特流 udp 跟踪器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8625115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com