Control a Tor server using the socket connection.
The spec of the control protocol: https://gitweb.torproject.org/torspec.git/blob_plain/HEAD:/control-spec.txt
/** * Quote function. */ public function testQuote() { // Must return "test" $this->assertEquals('"test"', TorControl::quote('test')); // Must return "\"" $this->assertEquals('"\\""', TorControl::quote('"')); // Must return "\\" $this->assertEquals('"\\\\"', TorControl::quote('\\')); // Must return "\\\"" $this->assertEquals('"\\\\\\""', TorControl::quote('\\"')); }
public function changeNYM() { // Connect to the TOR server using password authentication $tc = new TorControl(['hostname' => 'localhost', 'port' => 9051, 'password' => 'new_tor_password', 'authmethod' => 1]); $tc->connect(); $tc->authenticate(); $res = $tc->executeCommand('SIGNAL NEWNYM'); echo getColoredMessage('NYM: ' . $res[0]['code'] . ': ' . $res[0]['message'] . PHP_EOL, 'warning'); $tc->quit(); }