Change tor proxy by tor control protocol

2019-08-27 16:24发布

问题:

I want to change automaticaly tor proxy settings in PHP through tor control protocol, but I don't know the appropriate command to do that. I tried :

GETCONF HTTPProxyAddr

or

GETCONF HTTPProxyPort

but tor answered :

510 Unrecognized command

What are the keywords to control the proxy used in front of tor? Thanks

回答1:

The correct command to regenerate a tor route is SIGNAL NEWNYM. Here's some quick sample code:

<?php
    $sock = fsockopen( 'unix://control' );
    fwrite( $sock, "AUTHENTICATE\n" );
    echo fread( $sock, 128 );
    fwrite( $sock, "SIGNAL NEWNYM\n" );
    echo fread( $sock, 128 );
?>

Look at Section 3.7 of the Control Specification.

Note that the proxy address and port stay the same and never change. It's the route that is changed. If you want to authenticate and grab the proxy address and port via control issue a GETCONF.

However, HTTPProxyAddr is not a valid configuration variable, HTTPProxy is. A list of all configuration variables can be found here https://www.torproject.org/docs/tor-manual.html.en. Some versions of Tor did throw a 510 when an incorrect configuration variable was requested.