Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://www.linuxquestions.org/questions/linux-newbie-8/telnet-connect-to-address-127-0-0-1-connection-refused-4175452681/
- //http://w-shadow.com/blog/2008/06/20/tor-how-to-new-identity-with-php/
- //https://github.com/craig/ge.mine.nu/tree/master/tor-ctrl
- //https://stem.torproject.org/faq.html
- //https://stem.torproject.org/download.html
- <?php /**
- * Switch TOR to a new identity.
- **/
- function tor_new_identity($tor_ip='127.0.0.1', $control_port='9051', $auth_code=''){
- $fp = fsockopen($tor_ip, $control_port, $errno, $errstr, 30);
- if (!$fp) return false; //can't connect to the control port
- fputs($fp, "AUTHENTICATE $auth_code\r\n");
- $response = fread($fp, 1024);
- list($code, $text) = explode(' ', $response, 2);
- if ($code != '250') return false; //authentication failed
- //send the request to for new identity
- fputs($fp, "signal NEWNYM\r\n");
- $response = fread($fp, 1024);
- list($code, $text) = explode(' ', $response, 2);
- if ($code != '250') return false; //signal failed
- fclose($fp);
- return true;
- }
- /**
- * Load the TOR's "magic cookie" from a file and encode it in hexadecimal.
- **/
- function tor_get_cookie($filename){
- $cookie = file_get_contents($filename);
- //convert the cookie to hexadecimal
- $hex = '';
- for ($i=0;$i<strlen($cookie);$i++){
- $h = dechex(ord($cookie[$i]));
- $hex .= str_pad($h, 2, '0', STR_PAD_LEFT);
- }
- return strtoupper($hex);
- }
- $cookie = tor_get_cookie('/path/to/tor/data/dir/control_auth_cookie');
- if (tor_new_identity('127.0.0.01', '9051')) {
- echo "Identity switched!";
- }
- ?>
- //------------------------------------------------------
- python
- from stem import Signal
- from stem.control import Controller
- with Controller.from_port(port = 9051) as controller:
- controller.authenticate()
- controller.signal(Signal.NEWNYM)
- /python
- Comando
- echo 123456 > /var/lib/tor/control_auth_cookie
- echo -e 'AUTHENTICATE "123456"\r\nsignal NEWNYM\r\nQUIT' | nc localhost 9051
- Comando2
- [ -z 'pidof tor' ] || echo '::::MUDANDO IP TOR::::';pidof tor | xargs sudo kill -HUP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement