BitTorrent UDP 跟踪器响应

发布于 2024-12-22 21:27:35 字数 1210 浏览 4 评论 0原文

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

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

i have doubt how the udp announce response are handled as sugested in bep udp protocol specification

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)

but i am getting following error

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潦草背影 2024-12-29 21:27:35

看起来您正在向结构传递一个太大的字符串,可能是因为您收到了多个数据包。另外

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

,您似乎没有正确解析公告响应。请参阅此处了解 UDP 跟踪器数据包的格式。

It looks like you're passing a string to struct that's too big, perhaps because you're getting more than one packet. Try

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

Also, it appears that you are not parsing the announce response correctly. See here for the format of the UDP tracker packets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文