Class: Ronin::DB::IPAddress
- Defined in:
- lib/ronin/db/ip_address.rb
Overview
Represents IP addresses and their associated host names and MAC addresses.
Instance Attribute Summary collapse
-
#address ⇒ String
The IP Address.
-
#advisories ⇒ Array<Advisory>
The advisories that the IP Address is vulnerable to.
-
#host_name_ip_addresses ⇒ Array<HostNameIPAddress>
The host-names that the IP Address serves.
-
#host_names ⇒ Array<HostName>
The host-names associated with the IP Address.
-
#hton ⇒ String
The IP address, but in network byte-order.
-
#ip_address_mac_addresses ⇒ Array<IPAddressMACAddress>
The MAC Addresses associations.
-
#mac_addresses ⇒ Array<MACAddress>
The MAC Addresses associated with the IP Address.
-
#notes ⇒ Array<Note>
The associated notes.
-
#open_ports ⇒ Array<OpenPort>
The open ports of the host.
-
#organization_ip_addresses ⇒ Array<OrganizationIPAddress>
The association of IP addresses and organizations.
-
#organizations ⇒ Array<Organization>
The organizations that claim ownership of the IP address.
-
#os_guesses ⇒ Array<OSGuess>
Any OS guesses against the IP Address.
-
#oses ⇒ Array<OS>
Any OSes that the IP Address might be running.
-
#ports ⇒ Array<Port>
The ports of the host.
-
#version ⇒ Integer
Type of the address.
-
#vulnerabilities ⇒ Array<Vulnerability>
The vulnerabilities which reference the IP Address.
Attributes inherited from Address
Attributes included from Model::LastScannedAt
Class Method Summary collapse
-
.between(first_ip, last_ip) ⇒ Array<IPAddress>
Queries all IP address that are between the first IP address and last IP address.
-
.in_range(range) ⇒ Array<IPAddress>
Queries all IP addresses that exist in the range of IP addresses.
-
.v4 ⇒ Array<IPAddress>
Searches for all IPv4 addresses.
-
.v6 ⇒ Array<IPAddress>
Searches for all IPv6 addresses.
-
.with_host_name(name) ⇒ Array<IPAddress>
Searches for IP addresses associated with the given host name(s).
-
.with_mac_address(mac) ⇒ Array<IPAddress>
Searches for all IP addresses associated with specific MAC address(es).
-
.with_port_number(number) ⇒ Array<IPAddress>
Searches for IP addresses with the given open port(s).
Instance Method Summary collapse
-
#asn ⇒ ASN?
Queries the ASN record for the IP address.
-
#initialize(*arguments, **kwargs) ⇒ IPAddress
constructor
Initializes the IP address record.
-
#ipaddr ⇒ IPAddr
(also: #to_ip)
Returns an
IPAddr
object for the IP address. -
#recent_host_name ⇒ HostName
The host-name that was most recently used by the IP Address.
-
#recent_mac_address ⇒ MACAddress
The MAC Address that was most recently used by the IP Address.
-
#recent_os_guess ⇒ OS
The Operating System that was most recently guessed for the IP Address.
-
#to_i ⇒ Integer
Converts the address to an Integer.
Methods inherited from Address
Methods included from Model::LastScannedAt
Methods included from Model::Importable
Methods included from Model
Constructor Details
#initialize(*arguments, **kwargs) ⇒ IPAddress
Also assigns a default value to version
based on the address
.
Initializes the IP address record.
269 270 271 272 273 274 275 276 277 |
# File 'lib/ronin/db/ip_address.rb', line 269 def initialize(*arguments,**kwargs) super(*arguments,**kwargs) self.version ||= if ipaddr if ipaddr.ipv6? then 6 else 4 end end end |
Instance Attribute Details
#address ⇒ String
The IP Address.
39 |
# File 'lib/ronin/db/ip_address.rb', line 39 attribute :address, :string |
#advisories ⇒ Array<Advisory>
The advisories that the IP Address is vulnerable to.
129 |
# File 'lib/ronin/db/ip_address.rb', line 129 has_many :advisories, through: :vulnerabilities |
#host_name_ip_addresses ⇒ Array<HostNameIPAddress>
The host-names that the IP Address serves.
80 81 |
# File 'lib/ronin/db/ip_address.rb', line 80 has_many :host_name_ip_addresses, dependent: :destroy, class_name: 'HostNameIPAddress' |
#host_names ⇒ Array<HostName>
The host-names associated with the IP Address.
87 |
# File 'lib/ronin/db/ip_address.rb', line 87 has_many :host_names, through: :host_name_ip_addresses |
#hton ⇒ String
The IP address, but in network byte-order.
52 |
# File 'lib/ronin/db/ip_address.rb', line 52 attribute :hton, :binary |
#ip_address_mac_addresses ⇒ Array<IPAddressMACAddress>
The MAC Addresses associations.
66 67 |
# File 'lib/ronin/db/ip_address.rb', line 66 has_many :ip_address_mac_addresses, dependent: :destroy, class_name: 'IPAddressMACAddress' |
#mac_addresses ⇒ Array<MACAddress>
The MAC Addresses associated with the IP Address.
73 74 |
# File 'lib/ronin/db/ip_address.rb', line 73 has_many :mac_addresses, through: :ip_address_mac_addresses, class_name: 'MACAddress' |
#notes ⇒ Array<Note>
The associated notes.
154 |
# File 'lib/ronin/db/ip_address.rb', line 154 has_many :notes, dependent: :destroy |
#open_ports ⇒ Array<OpenPort>
The open ports of the host.
93 |
# File 'lib/ronin/db/ip_address.rb', line 93 has_many :open_ports, dependent: :destroy |
#organization_ip_addresses ⇒ Array<OrganizationIPAddress>
The association of IP addresses and organizations.
137 138 |
# File 'lib/ronin/db/ip_address.rb', line 137 has_many :organization_ip_addresses, class_name: 'OrganizationIPAddress', dependent: :destroy |
#organizations ⇒ Array<Organization>
The organizations that claim ownership of the IP address.
146 |
# File 'lib/ronin/db/ip_address.rb', line 146 has_many :organizations, through: :organization_ip_addresses |
#os_guesses ⇒ Array<OSGuess>
Any OS guesses against the IP Address.
105 106 |
# File 'lib/ronin/db/ip_address.rb', line 105 has_many :os_guesses, dependent: :destroy, class_name: 'OSGuess' |
#oses ⇒ Array<OS>
Any OSes that the IP Address might be running
112 113 |
# File 'lib/ronin/db/ip_address.rb', line 112 has_many :oses, through: :os_guesses, class_name: 'OS' |
#ports ⇒ Array<Port>
The ports of the host.
99 |
# File 'lib/ronin/db/ip_address.rb', line 99 has_many :ports, through: :open_ports |
#version ⇒ Integer
Type of the address.
59 |
# File 'lib/ronin/db/ip_address.rb', line 59 attribute :version, :integer |
#vulnerabilities ⇒ Array<Vulnerability>
The vulnerabilities which reference the IP Address.
121 |
# File 'lib/ronin/db/ip_address.rb', line 121 has_many :vulnerabilities, dependent: :destroy |
Class Method Details
.between(first_ip, last_ip) ⇒ Array<IPAddress>
Queries all IP address that are between the first IP address and last IP address.
192 193 194 195 196 197 198 199 |
# File 'lib/ronin/db/ip_address.rb', line 192 def self.between(first_ip,last_ip) first_ip_hton = IPAddr.new(first_ip).hton last_ip_hton = IPAddr.new(last_ip).hton hton = arel_table[:hton] where(hton.gteq(first_ip_hton).and(hton.lteq(last_ip_hton))) end |
.in_range(range) ⇒ Array<IPAddress>
Queries all IP addresses that exist in the range of IP addresses.
209 210 211 |
# File 'lib/ronin/db/ip_address.rb', line 209 def self.in_range(range) between(range.begin,range.end) end |
.v4 ⇒ Array<IPAddress>
Searches for all IPv4 addresses.
164 165 166 |
# File 'lib/ronin/db/ip_address.rb', line 164 def self.v4 where(version: 4) end |
.v6 ⇒ Array<IPAddress>
Searches for all IPv6 addresses.
176 177 178 |
# File 'lib/ronin/db/ip_address.rb', line 176 def self.v6 where(version: 6) end |
.with_host_name(name) ⇒ Array<IPAddress>
Searches for IP addresses associated with the given host name(s).
239 240 241 |
# File 'lib/ronin/db/ip_address.rb', line 239 def self.with_host_name(name) joins(:host_names).where(host_names: {name: name}) end |
.with_mac_address(mac) ⇒ Array<IPAddress>
Searches for all IP addresses associated with specific MAC address(es).
224 225 226 |
# File 'lib/ronin/db/ip_address.rb', line 224 def self.with_mac_address(mac) joins(:mac_addresses).where(mac_addresses: {address: mac}) end |
.with_port_number(number) ⇒ Array<IPAddress>
Searches for IP addresses with the given open port(s).
254 255 256 |
# File 'lib/ronin/db/ip_address.rb', line 254 def self.with_port_number(number) joins(:ports).where(ports: {number: number}) end |
Instance Method Details
#asn ⇒ ASN?
Queries the ASN record for the IP address.
316 317 318 |
# File 'lib/ronin/db/ip_address.rb', line 316 def asn ASN.containing_ip(ipaddr) end |
#ipaddr ⇒ IPAddr Also known as: to_ip
Returns an IPAddr
object for the IP address.
301 302 303 304 305 306 307 308 309 |
# File 'lib/ronin/db/ip_address.rb', line 301 def ipaddr @ipaddr ||= if self.address begin IPAddr.new(self.address) rescue IPAddr::InvalidAddressError nil end end end |
#recent_host_name ⇒ HostName
The host-name that was most recently used by the IP Address.
340 341 342 |
# File 'lib/ronin/db/ip_address.rb', line 340 def recent_host_name self.host_name_ip_addresses.order('created_at DESC').host_names.first end |
#recent_mac_address ⇒ MACAddress
The MAC Address that was most recently used by the IP Address.
328 329 330 |
# File 'lib/ronin/db/ip_address.rb', line 328 def recent_mac_address self.ip_address_mac_addresses.order('created_at DESC').mac_addresses.first end |
#recent_os_guess ⇒ OS
The Operating System that was most recently guessed for the IP Address.
353 354 355 |
# File 'lib/ronin/db/ip_address.rb', line 353 def recent_os_guess self.os_guesses.order('created_at DESC').oses.first end |
#to_i ⇒ Integer
Converts the address to an Integer.
367 368 369 |
# File 'lib/ronin/db/ip_address.rb', line 367 def to_i ipaddr.to_i end |