Class: UV::Ping
- Inherits:
-
Object
- Object
- UV::Ping
- Defined in:
- lib/uv-rays/ping.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#pingable ⇒ Object
readonly
Returns the value of attribute pingable.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#warning ⇒ Object
readonly
Returns the value of attribute warning.
Instance Method Summary collapse
-
#initialize(host, count: 1, interval: 1, timeout: 5) ⇒ Ping
constructor
A new instance of Ping.
- #ping ⇒ Object
Constructor Details
#initialize(host, count: 1, interval: 1, timeout: 5) ⇒ Ping
Returns a new instance of Ping.
11 12 13 14 15 |
# File 'lib/uv-rays/ping.rb', line 11 def initialize(host, count: 1, interval: 1, timeout: 5) @host = host @count = count @timeout = timeout end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def count @count end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def duration @duration end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def exception @exception end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def host @host end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def ip @ip end |
#pingable ⇒ Object (readonly)
Returns the value of attribute pingable.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def pingable @pingable end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def timeout @timeout end |
#warning ⇒ Object (readonly)
Returns the value of attribute warning.
17 18 19 |
# File 'lib/uv-rays/ping.rb', line 17 def warning @warning end |
Instance Method Details
#ping ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/uv-rays/ping.rb', line 19 def ping @ip = if IPAddress.valid?(@host) @host else nslookup(@host) end if @ip.nil? @pingable = false @exception = 'DNS lookup failed for both IPv4 and IPv6' return false end ipaddr = IPAddr.new @ip if ipaddr.ipv4? ping4(@ip, @count, @timeout) else ping6(@ip, @count, @timeout) end end |