Ejemplo n.º 1
0
<?php

require_once 'common.php';
use Dapphp\TorUtils\ControlClient;
use Dapphp\TorUtils\ProtocolError;
$tc = new ControlClient();
// Uncomment line below to enable debug output showing client<->controller communication
//$tc->setDebug(true);
try {
    $tc->connect();
    // connect to 127.0.0.1:9051
    $tc->authenticate();
} catch (\Exception $ex) {
    echo "Failed to create Tor control connection: " . $ex->getMessage() . "\n";
    exit;
}
// ask controller for tor version
$ver = $tc->getVersion();
echo "*** Connected ***\n*** Controller is running Tor {$ver} ***\n";
try {
    // get tor node's external ip, if known.
    // If Tor could not determine IP, an exception is thrown
    $address = $tc->getInfoAddress();
} catch (ProtocolError $pex) {
    $address = 'Unknown';
}
try {
    // get router fingerprint (if any) - clients will not have a fingerprint
    $fingerprint = $tc->getInfoFingerprint();
} catch (ProtocolError $pex) {
    $fingerprint = $pex->getMessage();
Ejemplo n.º 2
0
<?php

require_once 'common.php';
use Dapphp\TorUtils\ControlClient;
$tc = new ControlClient();
// Uncomment line below to enable debug output
//$tc->setDebug(true);
try {
    $tc->connect();
    // connect to 127.0.0.1:9051
    $tc->authenticate();
} catch (\Exception $ex) {
    echo "Failed to create Tor control connection: " . $ex->getMessage() . "\n";
    exit;
}
// register anonymous function as the event handler for async events
$tc->setAsyncEventHandler(function ($event, $data) {
    // depending on the $event - data may be an array or ProtocolReply object
    // for NS and NEWCONSENSUS events, $data is an array of RouterDescriptor objects keyed by fingerprint
    echo "Got event {$event}\n\n";
    var_dump($data);
});
// tell controller to notify of these events; could also pass events as an array
$tc->setEvents('NS NEWCONSENSUS SIGNAL CONF_CHANGED STATUS_GENERAL');
// also subscribe to ADDRMAP event and then try to resolve some names
// resolution is done in the background and nofications sent as ADDRMAP events
$tc->setEvents('ADDRMAP')->resolve(array('phpcaptcha.org', 'thepiratebay.se', 'www.torproject.org'));
// enable debug output and logging to file so we can see events received
// $tc->setDebug(1)->setDebugOutputFile(fopen('/tmp/tor.txt', 'w+'));
while (true) {
    // when reading a reply, if an async event is received then the callback given
Ejemplo n.º 3
0
<?php

require_once 'common.php';
use Dapphp\TorUtils\ControlClient;
use Dapphp\TorUtils\ProtocolError;
$tc = new ControlClient();
// Uncomment line below to enable debug output showing client<->controller communication
//$tc->setDebug(true);
try {
    $tc->connect();
    // connect to 127.0.0.1:9051
    $tc->authenticate();
} catch (\Exception $ex) {
    echo "Failed to create Tor control connection: " . $ex->getMessage() . "\n";
    exit;
}
try {
    // send arbitrary command; use GETINFO command with 'entry-guards' parameter
    $tc->sendData('GETINFO entry-guards');
    // read and parse controller response into a ProtocolReply object
    $reply = $tc->readReply();
    // show the status code of the command, and output the raw response
    printf("Reply status: %d\n", $reply->getStatusCode());
    echo $reply . "\n\n";
    // invokes __toString() to return the server reply
    // get an array of response lines
    $lines = $reply->getReplyLines();
    echo "Entry Guard(s):\n";
    for ($i = 1; $i < sizeof($lines); ++$i) {
        // iterate over each line skipping the first line which was the status
        // match the fingerprint, nickname, and router status of the entry guards
Ejemplo n.º 4
0
<?php

/**
 * Simple example showing how to send a signal to Tor to change your IP address
 */
require_once 'common.php';
use Dapphp\TorUtils\ControlClient;
$tc = new ControlClient();
try {
    $tc->connect('127.0.0.1', 9051);
    // connect to controller at 127.0.0.1:9051
    $tc->authenticate('password');
    // authenticate using hashedcontrolpassword "password"
    $tc->signal(ControlClient::SIGNAL_NEWNYM);
    // send signal to change IP
    echo "Signal sent - IP changed successfully!\n";
} catch (\Exception $ex) {
    echo "Signal failed: " . $ex->getMessage() . "\n";
}
Ejemplo n.º 5
0
<?php

require_once 'common.php';
use Dapphp\TorUtils\ControlClient;
use Dapphp\TorUtils\ProtocolError;
$tc = new ControlClient();
try {
    $tc->connect();
    // connect to 127.0.0.1:9051
    $tc->authenticate();
} catch (\Exception $ex) {
    echo "Failed to create Tor control connection: " . $ex->getMessage() . "\n";
    exit;
}
// Get configuration values for 4 Tor options
try {
    $config = $tc->getConf('BandwidthRate Nickname SocksPort ORPort');
    // $config is array where key is the option and value is the current setting
    foreach ($config as $keyword => $value) {
        echo "Config value {$keyword} = {$value}\n";
    }
} catch (ProtocolError $pe) {
    echo 'GETCONF failed: ' . $pe->getMessage();
}
echo "\n";
// Get configuration values with non-existent values
// GETCONF fails if any unknown options are present
try {
    $config = $tc->getConf('ORPort NonExistentConfigValue DirPort AnotherFakeValue');
} catch (ProtocolError $pe) {
    echo 'GETCONF failed: ' . $pe->getMessage();