Class: Ronin::MACAddress

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

Overview

Represents MAC addresses that can be stored in the Database.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Address

[], #inspect, parse, #to_s

Methods included from Model

included

Class Method Details

.extract(text) {|mac| ... } ⇒ Array<MACAddress>

Extracts MAC addresses from the given text.

Parameters:

  • text (String)

    The text to parse.

Yields:

  • (mac)

    The given block will be passed each extracted MAC address.

Yield Parameters:

Returns:

  • (Array<MACAddress>)

    If no block is given, an Array of MACAddress will be returned.

See Also:

  • 11.31.3.0


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ronin/mac_address.rb', line 68

def self.extract(text)
  return enum_for(:extract,text).to_a unless block_given?

  scanner = StringScanner.new(text)

  while scanner.skip_until(Regexp::MAC)
    yield parse(scanner.matched)
  end

  return nil
end

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.

Since:

  • 1.0.0



90
91
92
93
94
# File 'lib/ronin/mac_address.rb', line 90

def recent_ip_address
  self.ip_address_mac_addresses.all(
    :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.

Since:

  • 1.0.0



106
107
108
109
110
# File 'lib/ronin/mac_address.rb', line 106

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