Question

In order to resolve my project, I installed tor and privoxy on my virtual station (Debian). I found how to use curl and Tor proxy, but I can't change Ip adress at each curl_init().

here is my code:

#!/usr/bin/env php
<?php
function get_url($url)
{
// ensure PHP cURL library is installed
if(function_exists('curl_init'))
{
$timestart=microtime(true);

$ip = '127.0.0.1';
$port = '9050';
$auth = 'rebootip';
$command = 'signal NEWNYM';

$fp = fsockopen($ip,$port,$error_number,$err_string,10);

if(!$fp)
{
  echo "ERROR: $error_number : $err_string";
  return false;
}
else
{
        fwrite($fp,"AUTHENTICATE \"".$auth."\"\n");
        $received = fread($fp,512);
        fwrite($fp,$command."\n");
        $received = fread($fp,512);
}
fclose($fp);

$ch = curl_init();
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9050");
curl_setopt($ch, CURLOPT_PROXYTYPE, 7);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
$response = curl_exec($ch);
$error = curl_error($ch);
print_r($response."\n");
print_r($error."\n");
}
else // PHP cURL library not installed
{
echo 'Please install PHP cURL library';
}
}
echo get_url('http://ipinfo.io/');

is this-I need to change the configuration of "tor" and "privoxy" in order to change ip address ?

thanks in advance :)

Was it helpful?

Solution

To get a different exit node IP address, setup multiple Tor clients listening on port 9050, 9051, ... etc. Then on curl_init, change the proxy port to another available Tor client.

Once you have exhausted your current list of Tor clients, you can restart them to get another exit node. You can even send simple telnet commands directly to your Tor client to change the exit node.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top