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.
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#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 16 |
# File 'lib/uv-rays/ping.rb', line 11 def initialize(host, count: 1, interval: 1, timeout: 5) @host = host @count = count @interval = interval @timeout = timeout end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def count @count end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def duration @duration end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def exception @exception end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def host @host end |
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def interval @interval end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def ip @ip end |
#pingable ⇒ Object (readonly)
Returns the value of attribute pingable.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def pingable @pingable end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def timeout @timeout end |
#warning ⇒ Object (readonly)
Returns the value of attribute warning.
18 19 20 |
# File 'lib/uv-rays/ping.rb', line 18 def warning @warning end |
Instance Method Details
#ping ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/uv-rays/ping.rb', line 20 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, @interval, @timeout) else ping6(@ip, @count, @interval, @timeout) end end |