Class: Ronin::MACAddress
Overview
Represents MAC addresses that can be stored in the Database.
Class Method Summary collapse
-
.extract(text) {|mac| ... } ⇒ Array<MACAddress>
Extracts MAC addresses from the given text.
Instance Method Summary collapse
-
#recent_ip_address ⇒ IpAddress
The IP Address that most recently used the MAC Address.
-
#to_i ⇒ Integer
Converts the MAC address to an Integer.
Methods inherited from Address
Methods included from Model
Class Method Details
.extract(text) {|mac| ... } ⇒ Array<MACAddress>
Extracts MAC addresses from the given text.
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_address ⇒ IpAddress
The IP Address that most recently used the MAC Address.
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_i ⇒ Integer
Converts the MAC address to an Integer.
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 |