本文介绍了如何从HTTP跟踪器响应解析IP和端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向跟踪器发送请求并获得响应

I am sending a request to a tracker and get a response

d8:completei2e10:downloadedi1e10:incompletei1e8:intervali1971e12:min intervali985e5:peers18:\ 235'\ 027 \ 253 \ 000 \ 000 \ 331e57 \ 374- \ 033"\ 022,\ 270 \ 302e

如何从此响应获取对等列表或对等IP和端口

How to get Peers list or peer IP and port from this response

推荐答案

跟踪器的响应已已编码.
为了清楚起见,添加了一些空格:

The response from the tracker is bencoded.
Adding some whitespace for clarity:

d
 8:complete
  i2e
 10:downloaded
  i1e
 10:incomplete
  i1e
 8:interval
  i1971e
 12:min interval
  i985e
 5:peers
  18:\235'\027\253\000\000\331e57\374-\033"\022,\270\302
e

密钥:对等体,其具有18个字节的二进制字符串,作为 value 包含'compact = 1'-在以下格式中指定的格式: [BEP23-跟踪程序返回紧凑的对等列表] ,并且也在 [Wiki]

The key:peers that has a 18 bytes binary string as value contains peers in the 'compact=1'-form that is specified in: [BEP23 - Tracker Returns Compact Peer Lists] and also in [the wiki]

每个对等体都由 bigendian 中的6个字节,4个字节的IPv4 + 2个字节的PORT表示,因此18个字节的字符串适用于3个对等体.

Every peer is represented by 6 bytes, 4 bytes IPv4 + 2 bytes PORT in bigendian, so the 18 bytes string is for 3 peers.

\235 ' \027 \253 \000 \000=>157 39 23 171 0 0(0*256+0=0)          =>157.39.23.171:0
\331 e 5    7    \374 -   =>227 101 53 55 252 45(252*256+45=64557)=>227.101.53.55:64557
\033 " \022 ,    \270 \302=>27 34 18 44 184 192(184*256+192=47298)=>27.34.18.44:47298

(\ 235是157的八进制,'的ASCII值是39等)

(\235 is octal for 157, ' has ASCII value 39 etc.)

这篇关于如何从HTTP跟踪器响应解析IP和端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:31