Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

phlegx/macker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

17 Commits

Repository files navigation

Macker (The Mac Maker)

Real MAC address generator and vendor lookup.

Features

  • Generate random mac addresses
  • Generate random mac addresses by vendor
  • Lookup vendor by mac address
  • Fetch OUI list and use cache system
  • High configurable
  • See the documentation

Installation

Add this line to your application's Gemfile:

gem 'macker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install macker

Usage

Configuration

The following configuration is the default configuration of Macker. Store the configration code and load it at the beginning of Macker use. Rails users can create a file macker.rb in config/initializers to load the own Macker configuration.

Macker.configure do |config|
config.oui_full_url = 'http://linuxnet.ca/ieee/oui.txt' # Full URL of OUI text file
config.user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0' # A common user agent
config.ttl_in_seconds = 86_400 # Will expire the vendors in one day
config.cache = File.expand_path(File.dirname(__FILE__) + '/../../data/oui_*.txt') # Can be a string, pathname or proc
config.auto_expire = true # Expiration can be checked manually
config.auto_stale = true # Stale can be checked manually
end

Generat MAC address

"F8-4A-BF-B2-AA-C9" mac.to_i # => 272999927425737 mac.prefix # => "F84ABF" mac.name # => "Huawei Technologies Co.,ltd" mac.address # => ["D1, Huawei Industrial Base, Bantian, Longgang, Shenzhen", "Shenzhen Guangdong 518129", "Cn"] mac.full_address # => "D1, Huawei Industrial Base, Bantian, Longgang, Shenzhen, Shenzhen Guangdong 518129, Cn" mac.iso_code # => "CN" mac = Macker.generate(vendor: 'Apple, Inc.') # => # mac.to_s # => "64:E6:82:E5:CC:58" mac = Macker.generate(iso_code: 'US') # => # # Raise an exception Macker.generate!(iso_code: 'HELLO')">mac = Macker.generate
# => #
mac.to_s
# => "E9:C5:97:39:21:D4"

mac = Macker.generate(vendor: true)
# => #
mac.to_s('-')
# => "F8-4A-BF-B2-AA-C9"
mac.to_i
# => 272999927425737
mac.prefix
# => "F84ABF"
mac.name
# => "Huawei Technologies Co.,ltd"
mac.address
# => ["D1, Huawei Industrial Base, Bantian, Longgang, Shenzhen", "Shenzhen Guangdong 518129", "Cn"]
mac.full_address
# => "D1, Huawei Industrial Base, Bantian, Longgang, Shenzhen, Shenzhen Guangdong 518129, Cn"
mac.iso_code
# => "CN"

mac = Macker.generate(vendor: 'Apple, Inc.')
# => #
mac.to_s
# => "64:E6:82:E5:CC:58"

mac = Macker.generate(iso_code: 'US')
# => #

# Raise an exception
Macker.generate!(iso_code: 'HELLO')

Lookup MAC address

# Macker.lookup(mac) # => # # More examples Macker.lookup('64-E6-82-E5-CC-58') Macker.lookup('64E682E5CC58') Macker.lookup(110941201353816) Macker.lookup!(110941201353816)">Macker.lookup('64:E6:82:E5:CC:58')
# => #

Macker.lookup(mac)
# => #

# More examples
Macker.lookup('64-E6-82-E5-CC-58')
Macker.lookup('64E682E5CC58')
Macker.lookup(110941201353816)
Macker.lookup!(110941201353816)

MAC address

Macker::Address # Some methods of the address class mymac.name mymac.address mymac.iso_code mymac.to_i mymac.to_s mymac.oui? mymac.valid? mymac.broadcast? mymac.unicast? mymac.multicast? mymac.global_uniq? mymac.local_admin? mymac.next mymac.succ mymac.prefix mymac.full_address">mymac = Macker.lookup('64-E6-82-E5-CC-58')
mymac.class
# => Macker::Address

# Some methods of the address class
mymac.name
mymac.address
mymac.iso_code

mymac.to_i
mymac.to_s

mymac.oui?
mymac.valid?
mymac.broadcast?
mymac.unicast?
mymac.multicast?
mymac.global_uniq?
mymac.local_admin?

mymac.next
mymac.succ
mymac.prefix
mymac.full_address

Cache control

# Update OUI from cache (careful)
Macker.update
# => 2017-07-03 13:03:00 +0200

# Update OUI from remote (straight)
Macker.update(true)
# => 2017-07-03 13:04:00 +0200

# Vendor table with all base16 MAC prefixes as keys
Macker.prefix_table
# => "F8DA0C"=>{:name=>"Hon Hai..."}, ...

# Vendor table with all country iso codes as keys
Macker.iso_code_table
# => "CN"=>[{:name=>"Hon Hai..."} ... ]

# Vendor table with all country vendor names as keys
Macker.vendor_table
# => "Apple, Inc."=>[{:prefix=>...} ... ]

Macker.lapsed!
# => false

Macker.expire!
# => false

Macker.stale!
# => false

Macker.expired?
# => false

Macker.stale?
# => false

Macker.vendors_expiration
# => 2017-07-04 13:04:00 +0200

# Get configuration of Macker
Macker.config
# => #>

Contributors

Contributing

  1. Fork it ( https://github.com/[your-username]/macker/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The MIT License

Copyright (c) 2022 Phlegx Systems Technologies GmbH

About

Real MAC addresses generator and vendor lookup with MAC address handling.

Topics

Resources

Readme

License

MIT license

Stars

Watchers

Forks

Packages

Contributors

Languages