我想使用ssh,像这样:
ssh -D 9999 username@ip-address-of-ssh-server
Run Code Online (Sandbox Code Playgroud)
但在PHP CURL中,但我真的不知道如何做到这一点?
我注意到"CURLPROXY_SOCKS5"作为PHP的网站类型,但猜测这是行不通的,因为它不是真正的袜子,这是SSH ...
我目前正在使用此代码:
curl_setopt($ch, CURLOPT_PROXY, ‘ip:port');
Run Code Online (Sandbox Code Playgroud)
但我使用的是免费代理,而且速度慢且不可靠,我也通过此代理发送敏感信息.这就是为什么我想通过我信任的保存服务器代理它,但我只有ssh设置它并且它无法托管正确的代理.
您可以在 PHP 脚本中使用 libssh2 和 curl。
\n\n我不是 PHP 专家,但这里有一个粗略的例子:
\n\n<?php\n$connection = ssh2_connect(ip-address-of-ssh-server, 22);\nssh2_auth_pubkey_file($connection, \'username\', \'id_dsa.pub\', \'id_dsa\');\n$tunnel = ssh2_tunnel($connection, \'127.0.0.1\', 9999);\ncurl_setopt($ch, CURLOPT_PROXY, \xe2\x80\x98127.0.0.1:9999\'); \n// perform curl operations\n\n// The connection and tunnel will die at the and of the session.\n?>\nRun Code Online (Sandbox Code Playgroud)\n\n另一个需要考虑的选择是使用 sftp(通过 ssh 进行 ftp)而不是 CURL...这可能是在 PHP 中安全地将文件从一台服务器复制到另一台服务器的推荐方法...
\n\n更简单的例子:
\n\n<?php\n$connection = ssh2_connect(ip-address-of-ssh-server, 22);\nssh2_auth_password($connection, \'username\', \'password\');\nssh2_scp_send($connection, \'/local/filename\', \'/remote/filename\', 0644);\n?>\nRun Code Online (Sandbox Code Playgroud)\n
根据联机帮助页,-D 确实创建了一个袜子代理。
-D [bind_address:]port
Specifies a local ``dynamic'' application-level port forwarding.
This works by allocating a socket to listen to port on the local
side, optionally bound to the specified bind_address. Whenever a
connection is made to this port, the connection is forwarded over
the secure channel, and the application protocol is then used to
determine where to connect to from the remote machine. Currently
the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
as a SOCKS server. Only root can forward privileged ports. Dy-
namic port forwardings can also be specified in the configuration
file.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7235 次 |
| 最近记录: |