<?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();
<?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"; }