Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phlegx/macker
Real MAC addresses generator and vendor lookup with MAC address handling.
https://github.com/phlegx/macker
address gem generator lookup mac mac-address oui ouilookup random ruby
Last synced: 11 days ago
JSON representation
Real MAC addresses generator and vendor lookup with MAC address handling.
- Host: GitHub
- URL: https://github.com/phlegx/macker
- Owner: phlegx
- License: mit
- Created: 2017-07-03T15:31:14.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-21T17:52:05.000Z (about 2 years ago)
- Last Synced: 2024-10-23T02:51:46.981Z (16 days ago)
- Topics: address, gem, generator, lookup, mac, mac-address, oui, ouilookup, random, ruby
- Language: Ruby
- Homepage:
- Size: 1.01 MB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Macker (The Mac Maker)
[![Gem Version](https://badge.fury.io/rb/macker.svg)](https://rubygems.org/gems/macker)
[![Gem](https://img.shields.io/gem/dt/macker.svg)](https://rubygems.org/gems/macker)
[![Build Status](https://secure.travis-ci.org/phlegx/macker.svg?branch=master)](https://travis-ci.org/phlegx/macker)
[![Code Climate](https://codeclimate.com/github/phlegx/macker.svg)](https://codeclimate.com/github/phlegx/macker)
[![Inline Docs](http://inch-ci.org/github/phlegx/macker.svg?branch=master)](http://inch-ci.org/github/phlegx/macker)
[![License](https://img.shields.io/github/license/phlegx/macker.svg)](http://opensource.org/licenses/MIT)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](http://www.rubydoc.info/gems/macker)## Installation
Add this line to your application's Gemfile:
```ruby
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.```ruby
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
```ruby
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
```ruby
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
```ruby
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_codemymac.to_i
mymac.to_smymac.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
```ruby
# 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!
# => falseMacker.expire!
# => falseMacker.stale!
# => falseMacker.expired?
# => falseMacker.stale?
# => falseMacker.vendors_expiration
# => 2017-07-04 13:04:00 +0200# Get configuration of Macker
Macker.config
# => #>
```## Contributors
* Inspired by MacVendor [github.com/uceem/mac_vendor](https://github.com/uceem/mac_vendor).
* Inspired by MacAddressEui48 [github.com/cunchem/mac_address_eui48](https://github.com/cunchem/mac_address_eui48).## 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