【问题标题】:Read() Write() commands producing unwanted resource id #9Read() Write() 命令产生不需要的资源 id #9
【发布时间】: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


    【解决方案1】:

    我在 Google 上搜索到“在 '^' 标记处检测到无效输入”并找到了这个:

    https://learningnetwork.cisco.com/thread/28616

    引用它,

    On the switch you are connected to, does the prompt look similar to this:
    
    switch>
    
    If so, we need to type in "enable" to go into privileged mode, where the prompt will look like this:
    
    switch#
    

    【讨论】:

    • 嗯,我不认为是这样,因为我可以在当前模式下在 putty 中运行 ping 命令没有问题。我相信它在某种程度上与 Phpseclib 有关......
    • @LeeBronwin - 你用什么做你的路由器?你能发布完整的 SSH 日志吗?也许在 pastebin.com 或什么的?您的帖子已将Resource id #9 重复四次,然后似乎试图回显该命令。它正在做ping 172.1 ^6.1.254。这几乎就像第二个八位字节中的第二个 1 被替换为“^6”。有点让我觉得可能正在发送一些看起来像1 但不是的字符。它没有回显任何这样的字符,但也许它不会......而且你的 SO 帖子文本中没有任何这样的字符,但也许 SO 删除了它..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 2018-06-24
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多