Class: Scanner
- Inherits:
-
Object
- Object
- Scanner
- Defined in:
- lib/networkwatcherd/scanner.rb
Constant Summary collapse
- @@default_nd_value =
254
Instance Method Summary collapse
-
#initialize(nd = @@default_nd_value) ⇒ Scanner
constructor
A new instance of Scanner.
- #scan(ip_pattern = "192.168.1", time = 300, timeout = 50.5) ⇒ Object
Constructor Details
#initialize(nd = @@default_nd_value) ⇒ Scanner
Returns a new instance of Scanner.
6 7 8 9 10 11 12 |
# File 'lib/networkwatcherd/scanner.rb', line 6 def initialize (nd=@@default_nd_value) @nd = nd @ip_old_list = Array.new(@nd) @ip_new_list = Array.new(@nd) @ip_new_list.fill("") @ip_old_list.fill("") end |
Instance Method Details
#scan(ip_pattern = "192.168.1", time = 300, timeout = 50.5) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/networkwatcherd/scanner.rb', line 14 def scan(ip_pattern="192.168.1",time=300,timeout=50.5) #@ip_old_list ||= Array.new(@nd) @ip_old_list = @ip_new_list.map(&:clone) @ip_new_list = Array.new(@nd) @ip_new_list.fill("") IPScanner.network_devices(@nd,ip_pattern) { |d| @ip_new_list[d.value] = d } #Get the new fags. new_fags = [] (0..@nd).each do |n| if @ip_new_list[n] != "" and @ip_old_list[n] == "" new_fags.push(@ip_new_list[n]) end end #p new_fags if !new_fags.empty? Notification.send("New Devices",new_fags) if !new_fags.empty? end |