Class: RubyNessus::Version1::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-nessus/version1/port.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, number, protocol, raw_string) ⇒ Port

Creates A New Port Object Port.new("ssh",22,"tcp", str)

Parameters:

  • service (String)

    The Port Service.

  • number (Integer)

    The Port number.

  • protocol (String)

    The Port protocol.

  • raw (String)

    output string from nessus.



22
23
24
25
26
27
# File 'lib/ruby-nessus/version1/port.rb', line 22

def initialize(service, number, protocol, raw_string)
  @service = service
  @number = number
  @protocol = protocol
  @raw_string = raw_string
end

Instance Attribute Details

#numberBoolean (readonly)

Return false if the port object number is nil

Returns:

  • (Boolean)

    Return false if the port object number is nil



9
10
11
# File 'lib/ruby-nessus/version1/port.rb', line 9

def number
  @number
end

#protocolObject (readonly)

Port Protocol



11
12
13
# File 'lib/ruby-nessus/version1/port.rb', line 11

def protocol
  @protocol
end

#raw_stringObject (readonly)

Raw output string from nessus



13
14
15
# File 'lib/ruby-nessus/version1/port.rb', line 13

def raw_string
  @raw_string
end

#serviceObject (readonly)

Port Service



7
8
9
# File 'lib/ruby-nessus/version1/port.rb', line 7

def service
  @service
end

Class Method Details

.parse(str) ⇒ Object

Parse A passed port string and return a Port Object.

Examples:

Port.parse(port)

Returns:

  • (Object)

    New Port Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/ruby-nessus/version1/port.rb', line 34

def self.parse(str)
  @full_port = str
  components = str.match(/^([^\(]+)\((\d+)\/([^\)]+)\)/)

  if components
    return Port.new(components[1].strip, components[2].strip, components[3].strip, str)
  else
    return Port.new(false, false, false, str)
  end
end

Instance Method Details

#tcp?Boolean

Return true iF port protocol Ii tcp.

Returns:

  • (Boolean)

    Return True If The Port Protocol Is TCP.



48
49
50
# File 'lib/ruby-nessus/version1/port.rb', line 48

def tcp?
  @protocol == 'tcp'
end

#to_sString

Return the port as a string.

Examples:

port.to_s #=> https (443/tcp)

Returns:

  • (String)

    Return The Port As A String



64
65
66
67
68
69
70
# File 'lib/ruby-nessus/version1/port.rb', line 64

def to_s
  if @service && @number && @protocol
    "#{@service} (#{@number}/#{@protocol})"
  else
    @raw_string.to_s
  end
end

#udp?Boolean

Return true iF port protocol Ii udp.

Returns:

  • (Boolean)

    Return True If The Port Protocol Is UDP.



55
56
57
# File 'lib/ruby-nessus/version1/port.rb', line 55

def udp?
  @protocol == 'udp'
end