Class: Ronin::DB::MACAddress

Inherits:
Address
  • Object
show all
Defined in:
lib/ronin/db/mac_address.rb

Overview

Represents MAC addresses and their associated IP addresses.

Instance Attribute Summary collapse

Attributes inherited from Address

#created_at, #id

Attributes included from Ronin::DB::Model::LastScannedAt

#last_scanned_at

Instance Method Summary collapse

Methods inherited from Address

import, lookup, #to_s

Methods included from Ronin::DB::Model::LastScannedAt

included

Methods included from Ronin::DB::Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#addressString

The MAC address.

Returns:

  • (String)


37
# File 'lib/ronin/db/mac_address.rb', line 37

attribute :address, :string

#ip_address_mac_addressesArray<IPAddressMACAddress>

The IP Addresses the MAC Address hosts

Returns:



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

has_many :ip_address_mac_addresses, dependent: :destroy,
class_name: 'IPAddressMACAddress'

#ip_addressesArray<IPAddress>

The IP Addresses associated with the MAC Address

Returns:



57
58
# File 'lib/ronin/db/mac_address.rb', line 57

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

Instance Method Details

#recent_ip_addressIPAddress

The IP Address that most recently used the MAC Address.

Returns:

  • (IPAddress)

    The IP Address that most recently used the MAC Address.



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

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

#to_iInteger

Converts the MAC address to an Integer.

Returns:

  • (Integer)

    The network representation of the MAC address.



80
81
82
83
84
# File 'lib/ronin/db/mac_address.rb', line 80

def to_i
  self.address.split(':').reduce(0) do |bits,char|
    ((bits << 8) | char.hex)
  end
end