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



23
24
25
# File 'lib/nmap/xml/port.rb', line 23

def initialize(node)
  @node = node
end

Instance Method Details

#inspectString

Inspects the port.

Returns:

  • (String)

    The inspected port.

Since:

  • 1.0.0



110
111
112
# File 'lib/nmap/xml/port.rb', line 110

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



43
44
45
# File 'lib/nmap/xml/port.rb', line 43

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



33
34
35
# File 'lib/nmap/xml/port.rb', line 33

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



63
64
65
# File 'lib/nmap/xml/port.rb', line 63

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

#reason_ttlInteger

The reason TTL.

Returns:

  • (Integer)

Since:

  • 0.10.0



74
75
76
# File 'lib/nmap/xml/port.rb', line 74

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



86
87
88
89
90
# File 'lib/nmap/xml/port.rb', line 86

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



53
54
55
# File 'lib/nmap/xml/port.rb', line 53

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



100
101
102
# File 'lib/nmap/xml/port.rb', line 100

def to_s
  number.to_s
end