python – bittorrent udp tracker响应
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – bittorrent udp tracker响应,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1345字,纯文字阅读大概需要2分钟。
内容图文
我怀疑udp宣布响应是如何在bep 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
解决方法:
看起来你正在将一个字符串传递给结构太大,可能是因为你得到了多个数据包.尝试
action=struct.unpack(">HLLLLQQQ20s20sLLQ",res[:98])
此外,您似乎没有正确解析通知响应.有关UDP跟踪器数据包的格式,请参阅here.
内容总结
以上是互联网集市为您收集整理的python – bittorrent udp tracker响应全部内容,希望文章能够帮你解决python – bittorrent udp tracker响应所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。