开发者

Checking for internet connection [duplicate]

This question already has answers here: Check if In开发者_C百科ternet Connection Exists with Ruby? (7 answers) Closed 8 years ago.

How to check for internet connection using Ruby.


You could try using Net::HTTP and 'pinging' a reliable URL such as Google and check for an exception indicating they do not have an internet connection.


Using Ping is deprecated in Ruby 1.9.x as explained here: https://stackoverflow.com/a/8317838

A more future-proof, as well as more code-relevant solution would be the solution given by that answer, using open-uri and returning false on exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜