用R语言ping测试

Posted 在R与Python知耕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用R语言ping测试相关的知识,希望对你有一定的参考价值。

近来想解决 能 ping通服务器就开始下一步的操作,想了半天,

ping测试有以下方法,


ping通 示例如下:

> library(pingr)> > ping('www.baidu.com')[1] 38 64 23> > ping('220.181.38.150')[1] 60 23 54> > # OR use system command instead> > pingREsult1<-system('ping -n 1 www.baidu.com',intern=TRUE)> > pingREsult1[1] "" [2] "Pinging www.a.shifen.com [220.181.38.149] with 32 bytes of data:"[3] "Reply from 220.181.38.149: bytes=32 time=24ms TTL=48" [4] "" [5] "Ping statistics for 220.181.38.149:" [6] " Packets: Sent = 1, Received = 1, Lost = 0 (0% loss)," [7] "Approximate round trip times in milli-seconds:" [8] " Minimum = 24ms, Maximum = 24ms, Average = 24ms" > > PingResult2<-shell('ping -n 1 220.181.38.150',intern=TRUE)> > PingResult2[1] "" [2] "Pinging 220.181.38.150 with 32 bytes of data:" [3] "Reply from 220.181.38.150: bytes=32 time=53ms TTL=48" [4] "" [5] "Ping statistics for 220.181.38.150:" [6] " Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),"[7] "Approximate round trip times in milli-seconds:" [8] " Minimum = 53ms, Maximum = 53ms, Average = 53ms" 


ping不通,示例如下:

> library(pingr)> > ping('www.baidu.com')[1] NA NA NA> > ping('220.181.38.150')[1] NA NA NA> > # OR use system command instead> > pingREsult1<-system('ping -n 1 www.baidu.com',intern=TRUE)Warning message:In system("ping -n 1 www.baidu.com", intern = TRUE) : running command 'ping -n 1 www.baidu.com' had status 1> > pingREsult1[1] "Ping request could not find host www.baidu.com. Please check the name and try again."attr(,"status")[1] 1> > PingResult2<-shell('ping -n 1 220.181.38.150',intern=TRUE)> > PingResult2[1] "" [2] "Pinging 220.181.38.150 with 32 bytes of data:" [3] "Reply from 192.168.43.193: Destination host unreachable."[4] "" [5] "Ping statistics for 220.181.38.150:" [6] " Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),"> 

看明白了吗?

建议用R语言自带命令sysytem ,或者shell. 调包反应很慢。


END

以上是关于用R语言ping测试的主要内容,如果未能解决你的问题,请参考以下文章

用jquery实现Ping测试网络连接性

用片段替换某些东西

C语言写的程序,帮改成DLL

电脑查看延时得代码是ping后面是啥

R语言 Testlink excel 转XML 批量导入测试用例

在测试之间传递JUnit数据