Class: Nmap::Port

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

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Port

Creates a new Port object.

Parameters:

  • node (Nokogiri::XML::Element)

    The XML port element.



10
11
12
# File 'lib/nmap/port.rb', line 10

def initialize(node)
  @node = node
end

Instance Method Details

#numberInteger Also known as: to_i

The port number.

Returns:

  • (Integer)

    The number of the port.



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

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

#protocolSymbol

The protocol the port runs on

Returns:

  • (Symbol)

    The protocol of the port.



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

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

#reasonString

The reason the port was discovered.

Returns:

  • (String)

    How the port was discovered.



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

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



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/nmap/port.rb', line 74

def scripts
  unless @scripts
    @scripts = {}

    @node.xpath('script').each do |script|
      @scripts[script['id']] = script['output']
    end
  end

  return @scripts
end

#serviceString

The service the port provides.

Returns:

  • (String)

    The service detected on the port.



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

def service
  @service ||= if (service = @node.at('service/@name'))
                 service.inner_text
               end
end

#stateSymbol

The state of the port.

Returns:

  • (Symbol)

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



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

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.



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

def to_s
  number.to_s
end