ipscanner 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ipscanner.rb +5 -18
  2. metadata +2 -2
@@ -5,27 +5,14 @@
5
5
  require 'socket'
6
6
 
7
7
  class IPScanner
8
-
9
- def initialize(ip_base='192.168.1.')
10
- @ip_base = ip_base
11
- @a = []
12
- threads = (1..254).map{|i| Thread.new {ip = ip_base + i.to_s; @a << i if pingecho(ip, 1)}}
13
- threads.join
14
- end
15
8
 
16
- def self.run(ip_base='192.168.1.')
9
+ def self.scan(ip_base='192.168.1.', range=1..254, t=1)
17
10
  a = []
18
- threads = (1..254).map{|i| Thread.new {ip = ip_base + i.to_s; a << i if pingecho(ip_base + i.to_s, 1) }}
19
- threads.join
20
- a.sort.map{|x| ip_base + x.to_s}
11
+ (range).map{|i| Thread.new {a << i if pingecho(ip_base+i.to_s, t) }}.join
12
+ sleep t + 0.25
13
+ a.map{|x| ip_base + x.to_s}
21
14
  end
22
-
23
- def self.scan(ip_base='192.168.1.') self.run end
24
-
25
- def to_a()
26
- @a.sort.map{|x| @ip_base + x.to_s}
27
- end
28
-
15
+
29
16
  def self.pingecho(host, timeout=5, service="echo")
30
17
  begin
31
18
  timeout(timeout) do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ipscanner
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Robertson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-09 00:00:00 +00:00
13
+ date: 2011-12-10 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency