ruby ping for 1.9.1

前端 未结 4 1053
萌比男神i
萌比男神i 2021-02-03 10:37

I want to ping a site in my ruby code and saw that net-ping was a nice library to do this with. Unfortunately, when I tried to gem install net-ping I got the following error:

4条回答
  •  故里飘歌
    2021-02-03 11:01

    If by 'site' you mean website, then I wouldn't use ping. Ping will tell you if the host is up (unless a router or firewall is blocking ICMP), but it won't tell you if your web server or web app is responding properly.

    If that's the case, I'd recommend Net::HTTP from the standard library, or any of the other HTTP libraries. One way to do it is:

    def up?(site)
      Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK
    end
    
    up? 'www.google.com' #=> true
    

提交回复
热议问题