Class: Nmap::Port

Inherits:
Object
  • Object
show all
Includes:
Scripts
Defined in:
lib/nmap/port.rb

Overview

Wraps a port XML element.

Instance Method Summary collapse

Methods included from Scripts

#script_data, #scripts

Constructor Details

#initialize(node) ⇒ Port

Creates a new Port object.

Parameters:

  • node (Nokogiri::XML::Element)

    The XML port element.



18
19
20
# File 'lib/nmap/port.rb', line 18

def initialize(node)
  @node = node
end

Instance Method Details

#inspectString

Inspects the port.

Returns:

  • (String)

    The inspected port.



94
95
96
# File 'lib/nmap/port.rb', line 94

def inspect
  "#<#{self.class}: #{self}>"
end

#numberInteger Also known as: to_i

The port number.

Returns:

  • (Integer)

    The number of the port.



38
39
40
# File 'lib/nmap/port.rb', line 38

def number
  @number ||= @node['portid'].to_i
end

#protocolSymbol

The protocol the port runs on

Returns:

  • (Symbol)

    The protocol of the port.



28
29
30
# File 'lib/nmap/port.rb', line 28

def protocol
  @protocol ||= @node['protocol'].to_sym
end

#reasonString

The reason the port was discovered.

Returns:

  • (String)

    How the port was discovered.



58
59
60
# File 'lib/nmap/port.rb', line 58

def reason
  @reason ||= @node.at_xpath('state/@reason').inner_text
end

#serviceService

The fingerprinted service of the port.

Returns:

  • (Service)

    The service detected on the port.

Since:

  • 0.6.0



70
71
72
73
74
# File 'lib/nmap/port.rb', line 70

def service
  @service_info ||= if (service = @node.at_xpath('service'))
                      Service.new(service)
                    end
end

#stateSymbol

The state of the port.

Returns:

  • (Symbol)

    The state of the port (:open, :filtered or :closed).



48
49
50
# File 'lib/nmap/port.rb', line 48

def state
  @state ||= @node.at_xpath('state/@state').inner_text.to_sym
end

#to_sString

Converts the port to a String.

Returns:

  • (String)

    The port number.



84
85
86
# File 'lib/nmap/port.rb', line 84

def to_s
  number.to_s
end