-1

I'm trying to connect to a bitcoin node using a modified version of EasyBitcoin-PHP. Here are the modifications I made to make it work over TOR:

I created new fields for the TOR proxy: code-listing 1.1

...
public $response;//was there already

// TOR and other SOCK5 proxies
private $using_proxy;  #new
private $proxy_host;   #new
private $proxy_port;   #new

private $id = 0;//was there already
...

Then I created two new methods: code-listing 1.2

...
/**
 * @param string $host
 * @param int $port
 */
public  function set_proxy($host, $port)
{
    $this->proxy_host   = $host;
    $this->proxy_port   = $port;
}

/**
 * @param boolean|TRUE $proxy_usage
 */
public  function use_proxy($proxy_usage = TRUE)
{
    $this->using_proxy  = $proxy_usage;
}
...

Finally I added a few lines in the __call() method: code-listing 1.3

    // Build the cURL session
    $curl    = curl_init("{$this->proto}://{$this->host}:{$this->port}/{$this->url}");

    $options = array(
        CURLOPT_HTTPAUTH       => CURLAUTH_BASIC,
        CURLOPT_USERPWD        => $this->username . ':' . $this->password,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_MAXREDIRS      => 10,
        CURLOPT_HTTPHEADER     => array('Content-type: application/json'),
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $request
    );

    //What Follows is new!!!
    if($this->using_proxy){
        $options[CURLOPT_PROXY]     = $this->proxy_host;
        $options[CURLOPT_PROXYPORT] = $this->proxy_port;
        $options[CURLOPT_PROXYTYPE] = CURLPROXY_SOCKS5_HOSTNAME;
    }

The fields and methods I created, and the extra lines I added in the __call() method are the same I use on my other TOR PHP/cURL projects (whenever I want PHP/cURL to connect to a site via TOR) and they work just fine.

I then installed and run the TOR Expert Bundle (on Windows) and use the following script to get the info from the bitcoin node.

code-listing 2

<?php
    require_once('easybitcoin.php');

    $bitcoin = new Bitcoin('username','password','6cmgzwu3x57dr6z7.onion');

    $bitcoin->set_proxy("127.0.0.1", "9050");
    $bitcoin->use_proxy();

    if($bitcoin->getinfo()){

    } else {
        var_dump($bitcoin->status);
        var_dump($bitcoin->error);
    }

And Here is what I get when running the script on a command prompt:

int(0)
string(50) "Can't complete SOCKS5 connection to 0.0.0.0:0. (5)"

And sometimes I get this:

int(0)
string(50) "Can't complete SOCKS5 connection to 0.0.0.0:0. (1)"
Paiku Han
  • 581
  • 2
  • 16
  • 38

1 Answers1

0

Problem solved. The script is perfect. The problem lay in the way the server was set.

Paiku Han
  • 581
  • 2
  • 16
  • 38