Class: Ronin::DB::HostName
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::HostName
- 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
-
#created_at ⇒ Time
When the host name was first created.
-
#email_addresses ⇒ Array<EmailAddress>
The email addresses that are associated with the host-name.
-
#host_name_ip_addresses ⇒ Array<HostNameIPAddress>
The IP Address associations.
-
#id ⇒ Integer
The primary ID of the host name.
-
#ip_addresses ⇒ Array<IPAddress>
The IP Addresses that host the host name.
-
#name ⇒ String
The address of the host name.
-
#open_ports ⇒ Array<OpenPort>
The open ports of the host.
-
#ports ⇒ Array<Port>
The ports of the host.
-
#urls ⇒ Array<URL>
The URLs that point to this host name.
Attributes included from Model::LastScannedAt
Class Method Summary collapse
-
.import(name) ⇒ HostName
Creates a new host name.
-
.lookup(name) ⇒ HostName?
Looks up the host name.
-
.with_domain(name) ⇒ Array<HostName>
Searches for all host names sharing a canonical domain name.
-
.with_ip_address(ip) ⇒ Array<HostName>
Searches for host names associated with the given IP address(es).
-
.with_port_number(number) ⇒ Array<HostName>
Searches for host names with the given open port(s).
-
.with_tld(name) ⇒ Array<HostName>
Searches for all host names under the Top-Level Domain (TLD).
Instance Method Summary collapse
-
#recent_ip_address ⇒ IPAddress
The IP Address that was most recently used by the host name.
-
#to_s ⇒ String
Converts the host name to a String.
Methods included from Model::LastScannedAt
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#created_at ⇒ Time
When the host name was first created.
63 |
# File 'lib/ronin/db/host_name.rb', line 63 attribute :created_at, :datetime |
#email_addresses ⇒ Array<EmailAddress>
The email addresses that are associated with the host-name.
95 |
# File 'lib/ronin/db/host_name.rb', line 95 has_many :email_addresses |
#host_name_ip_addresses ⇒ Array<HostNameIPAddress>
The IP Address associations.
69 70 |
# File 'lib/ronin/db/host_name.rb', line 69 has_many :host_name_ip_addresses, dependent: :destroy, class_name: 'HostNameIPAddress' |
#id ⇒ Integer
The primary ID of the host name.
44 |
# File 'lib/ronin/db/host_name.rb', line 44 attribute :id, :integer |
#ip_addresses ⇒ Array<IPAddress>
The IP Addresses that host the host name.
76 77 |
# File 'lib/ronin/db/host_name.rb', line 76 has_many :ip_addresses, through: :host_name_ip_addresses, class_name: 'IPAddress' |
#name ⇒ String
The address of the host name.
50 |
# File 'lib/ronin/db/host_name.rb', line 50 attribute :name, :string |
#open_ports ⇒ Array<OpenPort>
The open ports of the host.
83 |
# File 'lib/ronin/db/host_name.rb', line 83 has_many :open_ports, through: :ip_addresses |
#ports ⇒ Array<Port>
The ports of the host.
89 |
# File 'lib/ronin/db/host_name.rb', line 89 has_many :ports, through: :ip_addresses |
#urls ⇒ Array<URL>
The URLs that point to this host name.
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.
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.
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.
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).
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).
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).
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_address ⇒ IPAddress
The IP Address that was 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_s ⇒ String
Converts the host name to a String.
215 216 217 |
# File 'lib/ronin/db/host_name.rb', line 215 def to_s self.name.to_s end |