Class: Nmap::XML::Port

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

Overview

Wraps a port XML element.

Since:

  • 1.0.0

Instance Method Summary collapse

Methods included from Scripts

#scripts

Constructor Details

#initialize(node) ⇒ Port

Creates a new Port object.

Parameters:

  • node (Nokogiri::XML::Element)

    The XML port element.

Since:

  • 1.0.0



21
22
23
# File 'lib/nmap/xml/port.rb', line 21

def initialize(node)
  @node = node
end

Instance Method Details

#inspectString

Inspects the port.

Returns:

  • (String)

    The inspected port.

Since:

  • 1.0.0



108
109
110
# File 'lib/nmap/xml/port.rb', line 108

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

#numberInteger Also known as: to_i

The port number.

Returns:

  • (Integer)

    The number of the port.

Since:

  • 1.0.0



41
42
43
# File 'lib/nmap/xml/port.rb', line 41

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

#protocolSymbol

The protocol the port runs on

Returns:

  • (Symbol)

    The protocol of the port.

Since:

  • 1.0.0



31
32
33
# File 'lib/nmap/xml/port.rb', line 31

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

#reasonString

The reason the port was discovered.

Returns:

  • (String)

    How the port was discovered.

Since:

  • 1.0.0



61
62
63
# File 'lib/nmap/xml/port.rb', line 61

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

#reason_ttlInteger

The reason TTL.

Returns:

  • (Integer)

Since:

  • 0.10.0



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

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

#serviceService

The fingerprinted service of the port.

Returns:

  • (Service)

    The service detected on the port.

Since:

  • 0.6.0



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

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).

Since:

  • 1.0.0



51
52
53
# File 'lib/nmap/xml/port.rb', line 51

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.

Since:

  • 1.0.0



98
99
100
# File 'lib/nmap/xml/port.rb', line 98

def to_s
  number.to_s
end