如何使用SSH调谐器设置curl


How to setup curl using SSH tunner

我有ssh,我想用cURL。

我的代码

<?php
$server = '123.456.789.012';
$port = 22;
$user = 'root';
$pass = '123456';
$connection = ssh2_connect($ip, $port, $methods, $callbacks);
if (!$connection) die('Connection failed');
$auth = ssh2_auth_password ($connection, $user, $pass);
$tunnel = ssh2_tunnel($connection, '127.0.0.1', 1080);
if(!$tunnel) die('error');
$url = 'http://dynupdate.no-ip.com/ip.php';
$proxy = '127.0.0.1:1080';
//$proxyauth = 'user:password';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);
echo "ok ".$curl_scraped_page;
?>
http://pastebin.com/8mtYwX2R

我使用CentOS os

谁能帮帮我

Curl主要用于web相关查询,我不确定如果您将它用于ssh, Curl是否会返回任何响应。我看到你的代码,似乎你没有做任何事情只是试图通过ssh登录并返回。但是,如果您想在ssh登录后运行一些命令,您可以使用ssh命令。如果您想复制一些文件,您也可以使用scp。所以让我确切地知道,当你通过curl进行ssh时,你想要达到什么目的。

libssh2是客户端。为了使ssh2_tunnel按照代码期望的方式运行,它必须在127.0.0.1::1080上启动服务器。而且不是普通的服务器,而是SOCKS5服务器。

下面是如何使用ssh2_tunnel:

$tunnel = ssh2_tunnel($connection, '127.0.0.1', 1080);
fputs($tunnel, "GET / HTTP/1.0'r'nHost: www.domain.tld'r'n'r'n");
while (true) {
    echo fgets($tunnel, 1024);
}