ipscanner 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ipscanner.rb +9 -0
- metadata +1 -1
data/lib/ipscanner.rb
CHANGED
@@ -6,6 +6,11 @@ require 'net/ping'
|
|
6
6
|
|
7
7
|
class IPScanner
|
8
8
|
|
9
|
+
def initialize(ip_base='192.168.1.')
|
10
|
+
@a = []
|
11
|
+
(1..254).each{|i| Thread.new {ip = ip_base + i.to_s; a << i if Net::Ping::TCP.new(ip, 'http').ping?}}
|
12
|
+
end
|
13
|
+
|
9
14
|
def self.run(ip_base='192.168.1.')
|
10
15
|
a = []
|
11
16
|
(1..254).each{|i| Thread.new {ip = ip_base + i.to_s; a << i if Net::Ping::TCP.new(ip, 'http').ping?}}
|
@@ -13,4 +18,8 @@ class IPScanner
|
|
13
18
|
end
|
14
19
|
|
15
20
|
def self.scan(ip_base='192.168.1.') self.run end
|
21
|
+
|
22
|
+
def to_a()
|
23
|
+
@a.sort.map{|x| ip_base + x.to_s}
|
24
|
+
end
|
16
25
|
end
|