Class: Ronin::DB::HostName

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model, Model::Importable, Model::LastScannedAt
Defined in:
lib/ronin/db/host_name.rb

Overview

Represents host names and their associated IP addresses.

Instance Attribute Summary collapse

Attributes included from Model::LastScannedAt

#last_scanned_at

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::LastScannedAt

included

Methods included from Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#created_atTime

When the host name was first created.

Returns:

  • (Time)


63
# File 'lib/ronin/db/host_name.rb', line 63

attribute :created_at, :datetime

#email_addressesArray<EmailAddress>

The email addresses that are associated with the host-name.

Returns:



95
# File 'lib/ronin/db/host_name.rb', line 95

has_many :email_addresses

#host_name_ip_addressesArray<HostNameIPAddress>

The IP Address associations.

Returns:



69
70
# File 'lib/ronin/db/host_name.rb', line 69

has_many :host_name_ip_addresses, dependent: :destroy,
class_name: 'HostNameIPAddress'

#idInteger

The primary ID of the host name.

Returns:

  • (Integer)


44
# File 'lib/ronin/db/host_name.rb', line 44

attribute :id, :integer

#ip_addressesArray<IPAddress>

The IP Addresses that host the host name.

Returns:



76
77
# File 'lib/ronin/db/host_name.rb', line 76

has_many :ip_addresses, through:    :host_name_ip_addresses,
class_name: 'IPAddress'

#nameString

The address of the host name.

Returns:

  • (String)


50
# File 'lib/ronin/db/host_name.rb', line 50

attribute :name, :string

#open_portsArray<OpenPort>

The open ports of the host.

Returns:



83
# File 'lib/ronin/db/host_name.rb', line 83

has_many :open_ports, through: :ip_addresses

#portsArray<Port>

The ports of the host.

Returns:



89
# File 'lib/ronin/db/host_name.rb', line 89

has_many :ports, through: :ip_addresses

#urlsArray<URL>

The URLs that point to this host name.

Returns:



101
# File 'lib/ronin/db/host_name.rb', line 101

has_many :urls, class_name: 'URL'

Class Method Details

.import(name) ⇒ HostName

Creates a new host name.

Parameters:

  • name (String)

    The host name.

Returns:

  • (HostName)

    The created host name record.



125
126
127
# File 'lib/ronin/db/host_name.rb', line 125

def self.import(name)
  create(name: name)
end

.lookup(name) ⇒ HostName?

Looks up the host name.

Parameters:

  • name (String)

    The raw host name.

Returns:

  • (HostName, nil)

    The found host name.



112
113
114
# File 'lib/ronin/db/host_name.rb', line 112

def self.lookup(name)
  find_by(name: name)
end

.with_domain(name) ⇒ Array<HostName>

Searches for all host names sharing a canonical domain name.

Parameters:

  • name (String)

    The canonical domain name to search for.

Returns:

  • (Array<HostName>)

    The matching host names.



187
188
189
190
191
192
193
# File 'lib/ronin/db/host_name.rb', line 187

def self.with_domain(name)
  name_column = self.arel_table[:name]

  name = sanitize_sql_like(name)

  where(name: name).or(where(name_column.matches("%.#{name}")))
end

.with_ip_address(ip) ⇒ Array<HostName>

Searches for host names associated with the given IP address(es).

Parameters:

  • ip (Array<String>, String)

    The IP address(es) to search for.

Returns:

  • (Array<HostName>)

    The matching host names.



140
141
142
# File 'lib/ronin/db/host_name.rb', line 140

def self.with_ip_address(ip)
  joins(:ip_addresses).where(ip_addresses: {address: ip})
end

.with_port_number(number) ⇒ Array<HostName>

Searches for host names with the given open port(s).

Parameters:

  • number (Array<Integer>, Integer)

    The open port(s) to search for.

Returns:

  • (Array<HostName>)

    The matching host names.



155
156
157
# File 'lib/ronin/db/host_name.rb', line 155

def self.with_port_number(number)
  joins(:ports).where(ports: {number: number})
end

.with_tld(name) ⇒ Array<HostName>

Searches for all host names under the Top-Level Domain (TLD).

Parameters:

  • name (String)

    The Top-Level Domain (TLD).

Returns:

  • (Array<HostName>)

    The matching host names.



170
171
172
173
174
# File 'lib/ronin/db/host_name.rb', line 170

def self.with_tld(name)
  name_column = self.arel_table[:name]

  where(name_column.matches("%.#{sanitize_sql_like(name)}"))
end

Instance Method Details

#recent_ip_addressIPAddress

The IP Address that was most recently used by the host name.

Returns:

  • (IPAddress)

    The IP Address that most recently used by the host name.



203
204
205
# File 'lib/ronin/db/host_name.rb', line 203

def recent_ip_address
  self.host_name_ip_addresses.order('created_at DESC').ip_addresses.first
end

#to_sString

Converts the host name to a String.

Returns:

  • (String)

    The host name.



215
216
217
# File 'lib/ronin/db/host_name.rb', line 215

def to_s
  self.name.to_s
end