Class: Nmap::Port

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

Overview

Wraps a port XML element.

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Port

Creates a new Port object.

Parameters:

  • node (Nokogiri::XML::Element)

    The XML port element.



15
16
17
# File 'lib/nmap/port.rb', line 15

def initialize(node)
  @node = node
end

Instance Method Details

#inspectString

Inspects the port.

Returns:

  • (String)

    The inspected port.



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

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

#numberInteger Also known as: to_i

The port number.

Returns:

  • (Integer)

    The number of the port.



35
36
37
# File 'lib/nmap/port.rb', line 35

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

#protocolSymbol

The protocol the port runs on

Returns:

  • (Symbol)

    The protocol of the port.



25
26
27
# File 'lib/nmap/port.rb', line 25

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

#reasonString

The reason the port was discovered.

Returns:

  • (String)

    How the port was discovered.



55
56
57
# File 'lib/nmap/port.rb', line 55

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

#scriptsHash{String => String}

The output from the NSE scripts ran against the open port.

Returns:

  • (Hash{String => String})

    The NSE script names and output.

Since:

  • 0.3.0



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

#serviceService

The fingerprinted service of the port.

Returns:

  • (Service)

    The service detected on the port.

Since:

  • 0.6.0



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

#stateSymbol

The state of the port.

Returns:

  • (Symbol)

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



45
46
47
# File 'lib/nmap/port.rb', line 45

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

#to_sString

Converts the port to a String.

Returns:

  • (String)

    The port number.



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

def to_s
  number.to_s
end