user3119862
user3119862

Reputation: 11

Torrent Scrape in PHP

i'm trying to scrape a torrent tracker for seeders and leechers using PHP. This is the hash value returned by torcahche: 7026AB638744F2BD2444033A8730DA146E15A886 Following trackers come with the torrent:

udp://tracker.openbittorrent.com:80/announce
udp://tracker.publicbt.com:80/announce
udp://tracker.ccc.de:80/announce

these are the methods that i have tried to get the info i need:

            $orig="7026AB638744F2BD2444033A8730DA146E15A886";
            $infoHash=$orig;
            $nfo='udp://tracker.openbittorrent.com:80/scrape?hash_id='.$infoHash;
            echo '<br>'.$nfo;
            $gitsl=$this->input->get($nfo);
            print_r($gitsl);

            $infoHash=pack('H',$orig);
            $nfo='udp://tracker.openbittorrent.com:80/scrape?hash_id='.$infoHash;
            echo '<br>'.$nfo;
            $gitsl=$this->input->get($nfo);
            print_r($gitsl);

            $infoHash=hex2bin($orig);
            $nfo='udp://tracker.openbittorrent.com:80/scrape?hash_id='.$infoHash;
            echo '<br>'.$nfo;
            $gitsl=$this->input->get($nfo);
            print_r($gitsl);

            $infoHash='%70%26%AB%63%87%44%F2%BD%24%44%03%3A%87%30%DA%14%6E%15%A8%86% ';
            $nfo='udp://tracker.openbittorrent.com:80/scrape?hash_id='.$infoHash;
            echo '<br>'.$nfo;
            $gitsl=$this->input->get($nfo);
            print_r($gitsl);

So getting nothing, the following questions have risen:

  1. Is the hash provided by torchache correct?
  2. Is a simple get request really all you need to get the info back?
  3. Is that even how you do a get request in codeigniter?
  4. Is there something wrong with the torrent file itself?

I've also tried multiple sites that allow you to manually type in hash info for a scrape, all unsucessful.

Hope somebody can help, cheers.

Upvotes: 1

Views: 1356

Answers (2)

Encombe
Encombe

Reputation: 2090

Repeating my answer from this question: UDP Tracker Scraping 1 script working other Not


The problem is that you are sending a http-scrape to a UDP-tracker.
UDP-trackers uses an entirely diffrent protocol: BEP15 - UDP Tracker Protocol for BitTorrent

Upvotes: 1

mariobgr
mariobgr

Reputation: 2201

Well, first of all, you don't to a GET request like that. This is how you READ the value of input.

Second, you are trying to perform a request through UDP. So you cannot just GET it, as the browser, or whatever, will do an HTTP request instead.

As stated in a comment in this site

The problem with UDP is that in case of TCP you have a tunnel, inside of which all data goes in both directions, but in case of UDP you send the UDP packet and have to open the port to listen for the answer (if it would come back). And if you get some data back, the packets can return in different order - you have to deal with this too.

That's why a normal GET or file_get_contents() won't do much good for you.

You can use stream_wrapper_register() to implement the wrapper for the UDP request.

Additionally, you should use $infoHash = urlencode(pack("H*", $orig)) to get the string needed to give to the tracker.

Upvotes: 0

Related Questions