I want using proxy/socks throw ssh server and i found nice example from here How do you proxy though a server using ssh (socks…) using php’s CURL? but example don't work, here is my code.
<?php
$connection = ssh2_connect("64.246.126.25", 22);
if(ssh2_auth_password($connection, "ubnt", "ubnt"))
{
if ($tunnel = ssh2_tunnel($connection, "127.0.0.1", 9999))
{
$url = "http://checkip.dyndns.com/";
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1:9999");
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
$result = curl_exec($ch);
echo $result;
}else{
echo "Tunnel creation failed.\n";
}
}
else
{
echo "failed!";
}
?>
When i excute this script i have error response:
Warning: ssh2_tunnel() [function.ssh2-tunnel]: Unable to request a channel from remote host in /home/domain.com/ssh2/index.php on line 7
Tunnel creation failed.
I will googled for this error and trying fix but can't solve problems.
Anyone can help me?