2012-02-27 47 views
0

我正在使用jsch庫使用ssh連接來連接服務器。然後,我打開一個「exec」通道來執行ping命令,以ping其他連接到該服務器的設備。確定ping是否已成功發送

例如

ping 192.168.0.128 

然後,它開始在控制檯打印出這是一個字符串,如下所示的響應: - 成功的ping:

PING 192.168.0.128 (192.168.0.128) 56(84) bytes of data. 
64 bytes from 192.168.0.128: icmp_req=1 ttl=64 time=0.253 ms 
64 bytes from 192.168.0.128: icmp_req=2 ttl=64 time=0.231 ms 

-unsuccessful平:

PING 192.168.0.126 (192.168.0.126) 56(84) bytes of data. 
From 192.168.0.7 icmp_seq=1 Destination Host Unreachable 
From 192.168.0.7 icmp_seq=2 Destination Host Unreachable 

如何我可以處理輸出以編程方式確定連接是否成功嗎?一個正則表達式模式?

回答

相關問題