Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the scrape URL for a torrent

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.

like image 209
C A Avatar asked Nov 05 '09 12:11

C A


2 Answers

You're passing in a hex-character representation of the info_hash. It should be a binary representation. To get unprintable bytes into the URL use URL-encoding:

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

(I'd also try to avoid encoding the _ in the info_hash parameter... not that it isn't correct, but it's the sort of thing I would expect some written-for-speed trackers to mess up.)

like image 118
bobince Avatar answered Oct 10 '22 03:10

bobince


My solution:

import binascii

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

Result:

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

More info: binascii.unhexlify

like image 30
Julien Avatar answered Oct 10 '22 04:10

Julien