Decode Torrent Hash of Torrent tracker scrape?

前端 未结 2 1632

I am using BEncoded PHP Library to decode the bencoded response from a Bittorrent tracker.

The response of Tracker is:

d5:filesd20:¼€™rÄ2ÞÊþVA  .]á^¦d8:c         


        
2条回答
  •  Happy的楠姐
    2021-02-20 16:51

    The link: http://wiki.vuze.com/w/Scrape posted by user3690414 pretty much explains what the different keys stands for.

    To interpret the raw bencoded string:

    d5:filesd20:¼€™rÄ2ÞÊþVA  .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee
    

    you need to understand how bencoding works: https://wiki.theory.org/BitTorrentSpecification#Bencoding

    The most essential to know here is that that every entry in a bencoded dictionary is a Key,Value-pair.
    Where Key is a byte string
    and Value one of the following types: byte string, integer, a list or a dictionary.

    With that in mind the raw string can be broken down like this:

    d               // The first d indicates the start of the Root dictionary
     5:files            // that has a Key with a 5 byte string name 'files',
      d                     // the value of the 'files'-key is a second dictionary
       20:¼€™rÄ2ÞÊþVA  .]á^¦    // that has a Key 20 byte = 160 bit big endian SHA1 info-hash
        d                       // the value of that key is a third dictionary
         8:complete                 // that has a Key with a 8 byte string name 'complete',
          i285e                         // the value of that key is a Integer=285
         10:downloaded              // that has a Key with a 10 byte string name 'downloaded',
          i22911e                       // the value of that key is a Integer=22911
         10:incomplete              // that has a Key with a 10 byte string name 'incomplete',
          i9e                           // the value of that key is a Integer=9
        e                       // this e indicates the end of the third dictionary
      e                     // this e indicates the end of the second dictionary
    e               // this e indicates the end of the Root dictionary
    

    Hope this helps to understand the output from 'bencoded.php'.

    edit.
    If you want to make the 160 bit big endian SHA1 info-hash [¼€™rÄ2ÞÊþVA .]á^¦]
    more human readable, I suggest that you output it as 40 byte hex-encoded string:
    0xBC801B9D9972C432DECAFE56410F092E5DE15EA6

提交回复
热议问题