Class: IPScanner
- Inherits:
-
Object
- Object
- IPScanner
- Defined in:
- lib/ipscanner.rb
Class Method Summary collapse
- .pingecho(host, timeout = 5, service = "echo") ⇒ Object
- .scan(ip_base = '192.168.1.', range = 1..254, t = 1) ⇒ Object
Class Method Details
.pingecho(host, timeout = 5, service = "echo") ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ipscanner.rb', line 17 def self.pingecho(host, timeout=5, service="echo") begin timeout(timeout) do s = TCPSocket.new(host, service) s.close end rescue Errno::ECONNREFUSED return true rescue Timeout::Error, StandardError return false end return true end |
.scan(ip_base = '192.168.1.', range = 1..254, t = 1) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/ipscanner.rb', line 10 def self.scan(ip_base='192.168.1.', range=1..254, t=1) a = [] (range).map{|i| Thread.new {a << i if pingecho(ip_base+i.to_s, t) }}.join sleep t + 0.25 a.map{|x| ip_base + x.to_s} end |