Class: Nmap::Port
- Inherits:
-
Object
- Object
- Nmap::Port
- Defined in:
- lib/nmap/port.rb
Overview
Wraps a port
XML element.
Instance Method Summary collapse
-
#initialize(node) ⇒ Port
constructor
Creates a new Port object.
-
#inspect ⇒ String
Inspects the port.
-
#number ⇒ Integer
(also: #to_i)
The port number.
-
#protocol ⇒ Symbol
The protocol the port runs on.
-
#reason ⇒ String
The reason the port was discovered.
-
#scripts ⇒ Hash{String => String}
The output from the NSE scripts ran against the open port.
-
#service ⇒ Service
The fingerprinted service of the port.
-
#state ⇒ Symbol
The state of the port.
-
#to_s ⇒ String
Converts the port to a String.
Constructor Details
#initialize(node) ⇒ Port
Creates a new Port object.
15 16 17 |
# File 'lib/nmap/port.rb', line 15 def initialize(node) @node = node end |
Instance Method Details
#inspect ⇒ String
Inspects the port.
111 112 113 |
# File 'lib/nmap/port.rb', line 111 def inspect "#<#{self.class}: #{self}>" end |
#number ⇒ Integer Also known as: to_i
The port number.
35 36 37 |
# File 'lib/nmap/port.rb', line 35 def number @number ||= @node['portid'].to_i end |
#protocol ⇒ Symbol
The protocol the port runs on
25 26 27 |
# File 'lib/nmap/port.rb', line 25 def protocol @protocol ||= @node['protocol'].to_sym end |
#reason ⇒ String
The reason the port was discovered.
55 56 57 |
# File 'lib/nmap/port.rb', line 55 def reason @reason ||= @node.at('state/@reason').inner_text end |
#scripts ⇒ Hash{String => String}
The output from the NSE scripts ran against the open port.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/nmap/port.rb', line 81 def scripts unless @scripts @scripts = {} @node.xpath('script').each do |script| @scripts[script['id']] = script['output'] end end return @scripts end |
#service ⇒ Service
The fingerprinted service of the port.
67 68 69 70 71 |
# File 'lib/nmap/port.rb', line 67 def service @service_info ||= if (service = @node.at('service')) Service.new(service) end end |
#state ⇒ Symbol
The state of the port.
45 46 47 |
# File 'lib/nmap/port.rb', line 45 def state @state ||= @node.at('state/@state').inner_text.to_sym end |
#to_s ⇒ String
Converts the port to a String.
101 102 103 |
# File 'lib/nmap/port.rb', line 101 def to_s number.to_s end |