php - PHP - SSH 连接中的 Telnet 连接/命令
问题描述
我有我的网络拓扑:machine_1、server_1 和 machine_2。
我正在开发一个将托管在 machine_1 中的应用程序。该应用程序的功能之一是通过 ssh 连接(我使用过 ssh2_exec)连接到 server_1,然后 server_1 能够到达 machine_2。
我想要做的是在这个 server_1 内发送一个 telnet 命令到 machine_2。由于我已经通过 ssh2_exec 命令连接到 server_1,有没有办法建立这个 telnet 连接,然后在 PHP 中发送 telnet 命令?
*obs:我只能通过从 server_1 建立的 telnet 连接将命令发送到 machine_2。
<?php
function rebootMachine() {
$original_Timeout=ini_get('default_socket_timeout');
ini_set('default_socket_timeout',10);
//IP addresses of the Server and the Machine
$server_ip = 10.0.0.1 ;
$machine_2= 10.10.0.1;
$command =“ system:REBOOT”;
//Telnet port to the Machine
$port_telnet = 49150;
$connection=@ssh2_connect($server_ip,22);
if(false==$connection){
echo "Server is unreacheable";
}else{
//conection the the Server
$auth=@ssh2_auth_password($connection, 'username','password');
if(false==$auth){
echo 'Authentication failed';
}else{
//Conection to the machine_2 by Telnet
$stream=@ssh2_exec($connection, 'telnet $machine_2 $port_telnet');
if (false==$stream){
echo 'error';
}else{
//command to reboot the Machine
}
fclose($stream);
}
}
}
解决方案
推荐阅读
- javascript - 如何使用连接到 Node-red 的 Javascript 设置 websocket
- android - Android App 的日志文件位置建议是什么?
- sql - IF 当另一个存储过程产生零时
- laravel - 使用第二个 whereHas 和“LIKE”进行非常慢的查询
- authentication - Actionscript 3.0:如何在主窗口和弹出窗口之间进行通信,直到主窗口获得服务器登录响应
- python - 如何使用带有条件的python boto3代码在s3存储桶中创建一个文件夹
- python - 可以使用数据类的类型化成员在没有自定义编码器/解码器的情况下进行序列化/反序列化吗?
- flutter - 如何在颤动中为文本添加边距
- python - 将请求帖子应用于熊猫数据框中的文本并保存在数据框中
- python-3.x - 除法运算在 Python 中产生的最后一位十进制数字的结果与常规 calc 的结果不同