Class: IPScannerPlus
- Inherits:
-
Object
- Object
- IPScannerPlus
- Defined in:
- lib/ipscannerplus.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(devices: nil, ports: nil) ⇒ IPScannerPlus
constructor
A new instance of IPScannerPlus.
- #lookup(service: nil, port: nil) ⇒ Object
- #scan ⇒ Object
Constructor Details
#initialize(devices: nil, ports: nil) ⇒ IPScannerPlus
Returns a new instance of IPScannerPlus.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ipscannerplus.rb', line 28 def initialize(devices: nil, ports: nil) @custom_ports = ports.strip.lines.map do |x| (x.chomp.split(/ +/,2) + ['']).take(2) end.to_h @known_ports = PORTS.strip.lines.map {|x| x.chomp.split(/ +/,2)}.to_h @devices = devices.strip.lines.map do |x| a = x.chomp.split(/ +/,3) [a[0], a[1..2]] end.to_h @ports = @known_ports.merge(@custom_ports) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
26 27 28 |
# File 'lib/ipscannerplus.rb', line 26 def result @result end |
Instance Method Details
#lookup(service: nil, port: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/ipscannerplus.rb', line 45 def lookup(service: nil, port: nil) if service then @result.find {|x| x.last.find {|y| y.last =~ /#{service}/i}} elsif port @result.find {|x| x.last.find {|y| y.first == port.to_i}} end end |
#scan ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ipscannerplus.rb', line 55 def scan() @result = IPScanner.scan.map do |ip| ports = FastPortScanner.scan(ip, ports: (1..1000).to_a \ + @custom_ports.keys.map(&:to_i)) [ [ip, @devices[ip[/\d+$/]]], ports.map { |port| [port, @ports[port.to_s]] } ] end end |