Sha256: 971e16589f4e7329edf10c0cac9b62b200483de9108f82edb755043d4daf5950

Contents?: true

Size: 810 Bytes

Versions: 3

Compression:

Stored size: 810 Bytes

Contents

require 'uri'
require 'resolv'
require "ipaddr"
require_relative 'l_util'

module LgPodPlugin

  class Ping
    attr_accessor :uri
    attr_accessor :ip
    attr_accessor :network_ok
    def initialize(url)
      self.uri = LUtils.git_to_uri(url)
    end

    def ping
      return false unless self.uri
      result = %x(ping #{uri.host} -t 1)
      if result.include?("timeout")
        return false
      end
      if result && result.include?("(") && result.include?("):")
        ip_address = result.split("(").last.split(")").first
        begin
          if IPAddr.new ip_address
            self.ip = ip_address
            return  true
          else
            return false
          end
        rescue
          return false
        end
      else
        return false
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lg_pod_plugin-1.1.3 lib/lg_pod_plugin/net-ping.rb
lg_pod_plugin-1.1.2 lib/lg_pod_plugin/net-ping.rb
lg_pod_plugin-1.1.1 lib/lg_pod_plugin/net-ping.rb