PHP Telnet Script to Connect to TOR and Refresh IP Address

This is a quick little script I wrote which will hopefully save some people the headache I went through getting this to work.  There is one other script out there which everone seems to be using, trouble is it was obviously written for a different version of PHP and does not work.

This has been tested with PHP version 5.3.5. on a windows platform.

The problem I was having was with carriage return and new lines.  Both /r and /n we registering as litteral characters no matter what I did.  Replacing them with “

” fixed the problem.  Also ensuring there are no spaces between the opening inverted commas, the line break and the closing inverted commas ie “

Dreamweaver has a habbit of trying to format your code so it looks nice and neat – in this case it was causing a bunch of spaces to be inserted in between the inverted commas.

Does that make sense?  probably not – but who cares – here’s the code any way.

<?php
function tor_telnet($ip,$port,$auth,$command) {

$fp = fsockopen($ip,$port,$error_number,$err_string,10);
if(!$fp) {  echo “ERROR: $error_number : $err_string
“;
return false;

} else {
fwrite($fp,’AUTHENTICATE “‘.$auth.’”
‘);

$received = fread($fp,512);
echo $received;

fwrite($fp,$command.’
‘);

echo “<BR>”;
$received = fread($fp,512);
// list($rcode,$explanation) = explode(‘ ‘,$received,2);
echo $received;

}
fclose($fp);
}

tor_telnet(’127.0.0.1′,’9051′,’password’,'signal NEWNYM’);
?>

 

Let me know if you find this useful.

 

<?php
function tor_telnet($ip,$port,$auth,$command) {

$fp = fsockopen($ip,$port,$error_number,$err_string,10);
if(!$fp) {  echo “ERROR: $error_number : $err_string
“;
return false;

} else {
fwrite($fp,’AUTHENTICATE “‘.$auth.’”
‘);

$received = fread($fp,512);
echo $received;

fwrite($fp,$command.’
‘);

echo “<BR>”;
$received = fread($fp,512);
// list($rcode,$explanation) = explode(‘ ‘,$received,2);
echo $received;

}
fclose($fp);
}

tor_telnet(’127.0.0.1′,’9051′,’test’,'signal NEWNYM’);
?>

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.