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.
-
#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.
-
#open_ports ⇒ Array<OpenPort>
The open ports of the host.
-
#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.
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.
228 229 230 231 232 233 234 235 236 |
# File 'lib/ronin/db/ip_address.rb', line 228 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 |
#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' |
#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 |
#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 |
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.
151 152 153 154 155 156 157 158 |
# File 'lib/ronin/db/ip_address.rb', line 151 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.
168 169 170 |
# File 'lib/ronin/db/ip_address.rb', line 168 def self.in_range(range) between(range.begin,range.end) end |
.v4 ⇒ Array<IPAddress>
Searches for all IPv4 addresses.
123 124 125 |
# File 'lib/ronin/db/ip_address.rb', line 123 def self.v4 where(version: 4) end |
.v6 ⇒ Array<IPAddress>
Searches for all IPv6 addresses.
135 136 137 |
# File 'lib/ronin/db/ip_address.rb', line 135 def self.v6 where(version: 6) end |
.with_host_name(name) ⇒ Array<IPAddress>
Searches for IP addresses associated with the given host name(s).
198 199 200 |
# File 'lib/ronin/db/ip_address.rb', line 198 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).
183 184 185 |
# File 'lib/ronin/db/ip_address.rb', line 183 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).
213 214 215 |
# File 'lib/ronin/db/ip_address.rb', line 213 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.
275 276 277 |
# File 'lib/ronin/db/ip_address.rb', line 275 def asn ASN.containing_ip(ipaddr) end |
#ipaddr ⇒ IPAddr Also known as: to_ip
Returns an IPAddr
object for the IP address.
260 261 262 263 264 265 266 267 268 |
# File 'lib/ronin/db/ip_address.rb', line 260 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.
299 300 301 |
# File 'lib/ronin/db/ip_address.rb', line 299 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.
287 288 289 |
# File 'lib/ronin/db/ip_address.rb', line 287 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.
312 313 314 |
# File 'lib/ronin/db/ip_address.rb', line 312 def recent_os_guess self.os_guesses.order('created_at DESC').oses.first end |
#to_i ⇒ Integer
Converts the address to an Integer.
326 327 328 |
# File 'lib/ronin/db/ip_address.rb', line 326 def to_i ipaddr.to_i end |