开发者

PHP: UDP tracker scrape example [closed]

Closed. This question needs to be more focused. It 开发者_JAVA技巧is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 9 years ago.

Improve this question

I haven't used PHP sockets and am a bit confused. Can someone give me an example of a UDP tracker scrape, using the standard protocol for connecting a UDP tracker?

Protocol: http://www.rasterbar.com/products/libtorrent/udp_tracker_protocol.html

If no one is willing to write a complete example, then can someone give me an example of how the data has to be formatted before sent through the socket?


A simple example how to send a raw udp packet

<?php
$frame = array(
    array(1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1),
    array(1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1),
    array(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1),
    array(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1),
    array(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1),
    array(1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1),
    array(1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1),
    array(1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1)
);

send_frame($frame, 1500);

/**
 * Sends 18x8 MCUF-UDP packet to target host.
 *
 * see also:
 * wiki.blinkenarea.org/index.php/MicroControllerUnitFrame
 *
 * @param array    $frame 18x8 '0' or '1'
 * @param int    $delay delay in msec
 * @param string    $host target host
 * @param int    $port target port (udp)
 */
function send_frame($frame, $delay, $host="192.168.0.23", $port=2323) {
    $header = "\x23\x54\x26\x66\x00\x08\x00\x12\x00\x01\x00\xff";
    $buf = $header;
    for ($i=0;$i<8;$i++) {
        for ($j=0;$j<18;$j++) {
            if ($frame[$i][$j]) {
                $buf.="\xff";
            } else  {
                $buf.="\x00";
            }
        }
    }
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    socket_sendto($socket, $buf, strlen($buf), 0, $host, $port);
    socket_close($socket);
    usleep($delay*1000);
}
?>


I wrote a class for scraping torrents: https://github.com/johannes85/PHP-Torrent-Scraper Feel free to use and read it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜