【发布时间】:2016-11-26 20:04:09
【问题描述】:
我正在尝试使用 read() 和 write() 命令在服务器上运行一些 ping 命令。我正在使用连接到 Net_ssh2 的 phpseclib,但是当我尝试获取结果并查看 echo $this->ssh->getLog(); 中发生了什么时
这是进入路由器的 ssh:
$this->ssh->write('ssh '.$this->userid.'@'.$this->testIPAddress);
$this->ssh->write("\n");
$this->ssh->read('Password:');
$this->ssh->write($this->passwd);
$this->ssh->write("\n");
$this->ssh->read('Welcome');
从那里我收到登录该路由器的成功消息,然后我运行以下 ping 命令:
$this->ssh->write("ping 172.11.1.221");
$this->ssh->write("\n");
$testLineShowResult = $this->ssh->read('Type');
这是日志返回的内容:
<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0005, network: 0.0001s)
00000000 00:00:00:01:00:00:00:01:35 ........5
<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0007, network: 0.0001s)
00000000 00:00:00:01:00:00:00:01:34 ........4
<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0022, network: 0.0001s)
00000000 00:00:00:01:00:00:00:02:0d:0a ..........
<- NET_SSH2_MSG_CHANNEL_DATA (since last: 0.0018, network: 0.0001s)
00000000 00:00:00:01:00:00:00:9c:52:65:73:6f:75:72:63:65 ........Resource
00000010 20:69:64:20:23:39:52:65:73:6f:75:72:63:65:20:69 id #9Resource i
00000020 64:20:23:39:52:65:73:6f:75:72:63:65:20:69:64:20 d #9Resource id
00000030 23:39:52:65:73:6f:75:72:63:65:20:69:64:20:23:39 #9Resource id #9
00000040 52:65:73:6f:75:72:63:65:20:69:64:20:23:39:70:69 Resource id #9pi
00000050 6e:67:20:31:37:32:2e:31:20:20:20:5e:36:2e:31:2e ng 172.1 ^6.1.
00000060 32:35:34:0d:0a:0d:0a:25:20:49:6e:76:61:6c:69:64 254....% Invalid
00000070 20:69:6e:70:75:74:20:64:65:74:65:63:74:65:64:20 input detected
00000080 61:74:20:27:5e:27:20:6d:61:72:6b:65:72:2e:0d:0a at '^' marker...
00000090 0d:0a:69:62:63:5f:34:35:37:39:33:30:30:39:30:37 ..ibc_4579300907
000000a0 5f:63:65:3e _ce>
如您所见,它多次打印资源 id #9...有人知道为什么吗?谢谢:D
【问题讨论】:
标签: php ssh phpseclib libssh2 net-ssh