【发布时间】:2023-01-14 08:16:20
【问题描述】:
下面给出的是我的问题。
- 我想要访问路由器 R2 并运行一些命令并获取输出。
- 无法从我的 PC 直接访问路由器 R2。要访问路由器 R2,我需要先访问直接连接到我的 PC 的路由器 R1,然后使用 ssh 命令访问 R2。
- 可以使用 ssh 访问路由器 R1。任何路由器都不允许 Telnet。
- 我找到了使用 PHP SSH 访问 R1 的代码,它工作正常。
<?php $connection = ssh2_connect('IP of R1', 22); ssh2_auth_password($connection, 'username', 'password'); $stream = ssh2_exec($connection, 'command'); stream_set_blocking($stream, true); $output = stream_get_contents($stream); echo "<pre>{$output}</pre>"; ?>- 使用上面的代码,我可以运行所有命令并从路由器 R1 获取输出。但是我无法运行命令来访问路由器 R2。要从我访问 R2,我需要从 R1 运行以下命令。
<#ssh <IP of R2> //then wait for username prompt enter username //wait for password prompt enter password //thats it.请提出一个解决方案,以便我可以通过 R1 访问 R2 并自动执行一些任务。
谢谢你。
【问题讨论】:
-
你可以从命令提示符/终端访问它吗?
标签: php ssh remote-access