Class: Nmap::OS

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/nmap/os.rb

Overview

Wraps the os XML element.

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ OS

Creates a new OS object.

Parameters:

  • node (Nokogiri::XML::Node)

    The node that contains the OS guessing information.



18
19
20
# File 'lib/nmap/os.rb', line 18

def initialize(node)
  @node = node
end

Instance Method Details

#classesArray<OSClass>

Parses the OS class information.

Returns:

  • (Array<OSClass>)

    The OS class information.



51
52
53
# File 'lib/nmap/os.rb', line 51

def classes
  each_class.to_a
end

#each(&block) ⇒ Object

Parses the OS match information.

See Also:



120
121
122
# File 'lib/nmap/os.rb', line 120

def each(&block)
  each_match(&block)
end

#each_class {|class| ... } ⇒ OS, Enumerator

Parses the OS class information.

Yields:

  • (class)

    Passes each OS class to the given block.

Yield Parameters:

  • class (OSClass)

    The OS class information.

Returns:

  • (OS, Enumerator)

    The OS information. If no block was given, an enumerator object will be returned.



35
36
37
38
39
40
41
42
43
# File 'lib/nmap/os.rb', line 35

def each_class
  return enum_for(__method__) unless block_given?

  @node.xpath("osmatch/osclass").each do |osclass|
    yield OSClass.new(osclass)
  end

  return self
end

#each_match {|match| ... } ⇒ OS, Enumerator

Parses the OS match information.

Yields:

  • (match)

    Passes each OS match to the given block.

Yield Parameters:

  • class (OSMatch)

    The OS match information.

Returns:

  • (OS, Enumerator)

    The OS information. If no block was given, an enumerator object will be returned.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/nmap/os.rb', line 68

def each_match
  return enum_for(__method__) unless block_given?

  @node.xpath("osmatch").map do |osclass|
    os_match = OSMatch.new(
      osclass['name'],
      osclass['accuracy'].to_i
    )

    yield os_match
  end

  return self
end

#fingerprintString

Parses the OS fingerprint used by Nmap.

Returns:

  • (String)

    The OS fingerprint.



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

def fingerprint
  @fingerprint ||= @node.at("osfingerprint/@fingerprint").inner_text
end

#matchesArray<OSMatch>

Parses the OS match information.

Returns:

  • (Array<OSMatch>)

    The OS match information.



89
90
91
# File 'lib/nmap/os.rb', line 89

def matches
  each_match.to_a
end

#ports_usedArray<Integer>

Parses the ports used for guessing the OS.

Returns:

  • (Array<Integer>)

    The ports used.



99
100
101
102
103
# File 'lib/nmap/os.rb', line 99

def ports_used
  @ports_used ||= @node.xpath("portused/@portid").map do |port|
    port.inner_text.to_i
  end
end