2016-07-22 182 views
0

我試圖用read()和write()命令在服務器上運行一些ping命令。我正在使用連接到Net_ssh2的phpseclib,但是當我嘗試獲取結果並查看echo $ this-> ssh-> getLog()中發生了什麼時,閱讀()寫()命令產生不需要的資源ID#9

這裏是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一堆tim es ...有人知道爲什麼嗎?感謝:d

回答

0

我Google'd 「在 '^' 標記無效輸入檢測」 和發現這一點:

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# 
+0

嗯,我不我認爲這是因爲我可以在沒有問題的情況下使用當前模式在putty中運行ping命令。我相信它在某種程度上與Phpseclib有關...... – LeeBronwin

+0

@LeeBronwin - 你在用什麼路由器?你能發佈完整的SSH日誌嗎?也許在pastebin.com或其他?你的文章有'資源ID#9'重複四次,然後似乎試圖回顯命令。它正在執行ping 172.1^6.1.254'。這幾乎就像第二個八位字節中的第二個被替換爲「^ 6」。有點讓我覺得也許一些角色被髮送,看起來像'1',但不是。這不是迴應任何像這樣的字符,但也許它不會..和你的SO帖子文本沒有任何像這樣的字符,但也許會刪除它.. – neubert