Class: Nessus::Version1::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/gemcache/ruby-nessus/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/gemcache/ruby-nessus/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/gemcache/ruby-nessus/ruby-nessus/Version1/port.rb', line 9

def number
  @number
end

#protocolObject (readonly)

Port Protocol



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

def protocol
  @protocol
end

#raw_stringObject (readonly)

Raw output string from nessus



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

def raw_string
  @raw_string
end

#serviceObject (readonly)

Port Service



7
8
9
# File 'lib/gemcache/ruby-nessus/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
44
45
46
47
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/port.rb', line 34

def Port.parse(str)
  begin
    @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

end

Instance Method Details

#tcp?Boolean

Return true iF port protocol Ii tcp.

Returns:

  • (Boolean)

    Return True If The Port Protocol Is TCP.



52
53
54
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/port.rb', line 52

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



68
69
70
71
72
73
74
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/port.rb', line 68

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

#udp?Boolean

Return true iF port protocol Ii udp.

Returns:

  • (Boolean)

    Return True If The Port Protocol Is UDP.



59
60
61
# File 'lib/gemcache/ruby-nessus/ruby-nessus/Version1/port.rb', line 59

def udp?
  @protocol == 'udp'
end