How to convert hash information on torrents for cleaning?

I have a hash torrent with a magnetic link. For example: fda164e7af470f83ea699a529845a9353cc26576 When I try to get information about leechers and peers, I should ask: http://tracker.publicbt.com/scrape?info_hash= ??? How do I convert the hash of information for this request? Is it encoding or url encoding? as? In PHP.

+3
source share
3 answers

This is a raw hexadecimal representation. Use pack()with Hto convert it. Then the url will encode it.

+3
source

,

r = ''
s = 'fda164e7af470f83ea699a529845a9353cc26576'
for n in range(0, len(s), 2):
    r += '%%%s' % s[n:n+2].upper()
print r

:% FD% A1% 64% E7% AF% 47% 0F% 83% EA% 69% 9A% 52% 98% 45% A9% 35% 3C% C2% 65% 76

.

: , 200 (ok), ...

+1

, - : bool $raw_output PHP: sha1, "true".

BDecode/DEncode . , Trackon, - .

, PHP - , - correct :

include('./path/to/BDecode.php');
include('./path/to/BEncode.php');

function getHash($torFile){
    $tfile = BDecode(file_get_contents($torFile));
    $infohash = sha1(BEncode($tfile["info"]), TRUE);

    return urlencode($infohash);
}

:

$hash = getHash('./path/to/.torrent');

Hope this helps someone. I was still scratching my head after reading many posts on how to get the right hash of information. I understand why this was not mentioned anywhere, but this argument was added in PHP 5. If you are not using PHP 5, you will have to convert the sha1 hash to the source binary after calculating it.

+1
source

Source: https://habr.com/ru/post/1755124/


All Articles