7

I've read the Bit-torrent specification and done a number of searches, trying to find out how I can get the seeds/peers/downloaded data from a torrent tracker (using Python). I can calculate the info hash from a Torrent no problem, which matches up with the info hash given by various working torrent applications.

However, when I try to get the information from the tracker I either timeout (the tracker is working) or get empty data, depending on what form I put the URL in:

http://tracker.openbittorrent.com/scrape?info_hash=a8c482902b1c735de462479721b011dc7b3d3558 - timeout

I was told that this should be 20 characters long, so took a substring, but this gives empty data.

http://tracker.openbittorrent.com/scrape?info_hash=a8c482902b1c735de462 - d5:filesdee

I think I have misunderstood something with how I should encode or make the infohash for the scrape URL, but can't for the life of me see where.

4

2 回答 2

6

您正在传递 info_hash 的十六进制字符表示。它应该是二进制表示。要将不可打印的字节放入 URL,请使用 URL 编码:

/scrape?info_hash=%A8%C4%82%90%2B%1Cs%5D%E4bG%97%21%B0%11%DC%7B%3D5X

(我也尽量避免_在 info_hash 参数中编码...并不是说它不正确,但这是我希望一些为速度而编写的跟踪器搞砸的事情。)

于 2009-11-05T13:19:41.093 回答
3

我的解决方案:

import binascii

binary_info_hash = binascii.unhexlify('79b193385de5b967175ca86073670fce0e45a324')
print binary_info_hash

结果:

y%B1%938%5D%E5%B9g%17%5C%A8%60sg%0F%CE%0EE%A3%24

更多信息:binascii.unhexlify

于 2014-05-02T14:45:01.167 回答