Sha256: 906991f184cea9cdc3215e2d3dff67464cba7b8a9e0063afa1a25fead59ea45f

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

require 'nmap/cpe'

module Nmap
  #
  # Represents an {OS} class.
  #
  class OSClass

    include CPE

    #
    # Initializes the os class.
    #
    # @param [Nokogiri::XML::Node] node
    #   The node that contains the OS Class information.
    #
    def initialize(node)
      @node = node
    end

    #
    # The OS type.
    #
    # @return [String]
    #
    def type
      @type ||= if @node['type']
                  @node['type'].to_sym
                end
    end

    #
    # The OS vendor.
    #
    # @return [String]
    #
    def vendor
      @vendor ||= @node.get_attribute('vendor')
    end

    #
    # The OS family.
    #
    # @return [Symbol, nil]
    #
    def family
      @family ||= @node.get_attribute('osfamily').to_sym
    end

    #
    # The OS generation.
    #
    # @return [Symbol, nil]
    #
    def gen
      @gen ||= if @node['osgen']
                 @node['osgen'].to_sym
               end
    end

    #
    # The accuracy of the OS class information.
    #
    # @return [Integer]
    #   Returns a number between 0 and 10.
    #
    def accuracy
      @accuracy ||= @node.get_attribute('accuracy').to_i
    end

    #
    # Converts the OS class to a String.
    #
    # @return [String]
    #   The String form of the OS class.
    #
    def to_s
      "#{self.type} #{self.vendor} (#{self.accuracy}%)"
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruby-nmap-0.10.0 lib/nmap/os_class.rb
ruby-nmap-0.9.3 lib/nmap/os_class.rb
ruby-nmap-0.9.2 lib/nmap/os_class.rb
ruby-nmap-0.9.1 lib/nmap/os_class.rb
ruby-nmap-0.9.0 lib/nmap/os_class.rb
ruby-nmap-0.8.0 lib/nmap/os_class.rb
ruby-nmap-0.7.0 lib/nmap/os_class.rb