ruby ping为1.9.1

我想在我的红宝石代码中ping一个网站,看到net-ping是一个很好的图书馆.不幸的是,当我尝试gem安装net-ping我得到以下错误

C:>gem install net-ping
ERROR: Error installing net-ping:
win32-open3 requires Ruby version < 1.9.0.

经过进一步的研究,我发现net-ping还没有用于1.9.X.有没有人有一个很好的代码,他们会愿意分享.

解决方法

您可以随时执行此操作,并使用正则表达式来解析结果或仅检查退出状态:
ping_count = 10
server = "www.google.com"
result = `ping -q -c #{ping_count} #{server}`
if ($?.exitstatus == 0) do
  puts "Device is up!"
end

Ping返回值可以检查:

The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from <sysexits.h>) if an error occurred.

http://www.manpagez.com/man/8/ping

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...