Class: IPScannerPlus
- Inherits:
-
Object
- Object
- IPScannerPlus
- Defined in:
- lib/ipscannerplus.rb
Overview
above info from en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers via
http://a0.jamesrobertson.eu/dynarex/ports-wellknown.xml
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.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/ipscannerplus.rb', line 228 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.
226 227 228 |
# File 'lib/ipscannerplus.rb', line 226 def result @result end |
Instance Method Details
#lookup(service: nil, port: nil) ⇒ Object
245 246 247 248 249 250 251 252 253 |
# File 'lib/ipscannerplus.rb', line 245 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
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/ipscannerplus.rb', line 255 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 |