Class: Ronin::OS

Inherits:
Object
  • Object
show all
Includes:
Model, Model::HasName
Defined in:
lib/ronin/os.rb

Overview

Represents an Operating System and pre-defines other common ones (linux, freebsd, openbsd, netbsd, osx, solaris, windows and unix).

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::HasName

included

Methods included from Model

included

Class Method Details

.predefine(name, attributes) ⇒ nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines a new predefined OS.

Examples:

OS.predefine :freebsd, 'FreeBSD'

Parameters:

  • name (Symbol, String)

    The method name to define for the predefined OS.

  • os_name (String)

    The name of the OS.

Returns:

  • (nil)


134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/ronin/os.rb', line 134

def OS.predefine(name,attributes)
  unless attributes[:name]
    raise(ArgumentError,"must specify the :name attribute")
  end

  super(name,attributes)

  # if no version was predefined, allow the predefined helper-methods
  # to accept a version argument
  unless attributes[:version]
    os_name = attributes[:name]

    meta_def(name) do |*arguments|
      attributes = predefined_attributes[name]
      version = if arguments.first
                  arguments.first.to_s
                end

      OS.first_or_create(attributes.merge(:version => version))
    end
  end

  return nil
end

Instance Method Details

#recent_ip_addressIPAddress

The IP Address that was most recently guessed to be using the Operating System.

Returns:

  • (IPAddress)

    The IP Address most recently guessed to be using the Operating System.

Since:

  • 1.0.0



67
68
69
70
71
72
73
# File 'lib/ronin/os.rb', line 67

def recent_ip_address
  relation = self.os_guesses.first(:order => [:created_at.desc])

  if relation
    return relation.ip_address
  end
end

#to_aryArray<String>

Splits the Operating System into multiple variables.

Examples:

os = OS.linux('2.6.31')
name, version = os

name
# => "Linux"
version
# => "2.6.31"

Returns:

  • (Array<String>)

    The name and version of the Operating System.

Since:

  • 1.0.0



114
115
116
# File 'lib/ronin/os.rb', line 114

def to_ary
  [self.name, self.version]
end

#to_sString

Converts the Operating System to a String.

Examples:

os = OS.new(:name => 'Linux', :version => '2.6.11')
os.to_s # => "Linux 2.6.11"

Returns:

  • (String)

    The OS name and version.



87
88
89
90
91
92
93
# File 'lib/ronin/os.rb', line 87

def to_s
  if self.version
    "#{self.name} #{self.version}"
  else
    super
  end
end