项目作者: phlegx

项目描述 :
Real MAC addresses generator and vendor lookup with MAC address handling.
高级语言: Ruby
项目地址: git://github.com/phlegx/macker.git
创建时间: 2017-07-03T15:31:14Z
项目社区:https://github.com/phlegx/macker

开源协议:MIT License

下载


Macker (The Mac Maker)

Gem Version
Gem
Build Status
Code Climate
Inline Docs
License

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:

  1. gem 'macker'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ 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.

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

Generat MAC address

  1. mac = Macker.generate
  2. # => #<Macker::Address:0x000000047e5cd0 @val=257034854932948, @name=nil, @address=nil, @iso_code=nil>
  3. mac.to_s
  4. # => "E9:C5:97:39:21:D4"
  5. mac = Macker.generate(vendor: true)
  6. # => #<Macker::Address:0x0000000477ed50 @val=272999927425737, @name="Huawei Technologies Co.,ltd", @address=["D1, Huawei Industrial..."], @iso_code="CN">
  7. mac.to_s('-')
  8. # => "F8-4A-BF-B2-AA-C9"
  9. mac.to_i
  10. # => 272999927425737
  11. mac.prefix
  12. # => "F84ABF"
  13. mac.name
  14. # => "Huawei Technologies Co.,ltd"
  15. mac.address
  16. # => ["D1, Huawei Industrial Base, Bantian, Longgang, Shenzhen", "Shenzhen Guangdong 518129", "Cn"]
  17. mac.full_address
  18. # => "D1, Huawei Industrial Base, Bantian, Longgang, Shenzhen, Shenzhen Guangdong 518129, Cn"
  19. mac.iso_code
  20. # => "CN"
  21. mac = Macker.generate(vendor: 'Apple, Inc.')
  22. # => #<Macker::Address:0x000000046e6910 @val=61638330009701, @name="Apple, Inc.", @address=["1 Infinite Loop", "Cupertino Ca 95014", "Us"], @iso_code="US">
  23. mac.to_s
  24. # => "64:E6:82:E5:CC:58"
  25. mac = Macker.generate(iso_code: 'US')
  26. # => #<Macker::Address:0x000000046b86f0 @val=161304050786, @name="The Weather Channel", @address=["Mail Stop 500", "Atlanta Ga 30339", "Us"], @iso_code="US">
  27. # Raise an exception
  28. Macker.generate!(iso_code: 'HELLO')

Lookup MAC address

  1. Macker.lookup('64:E6:82:E5:CC:58')
  2. # => #<Macker::Address:0x00000004699520 @val=110941201353816, @name="Apple, Inc.", @address=["1 Infinite Loop", "Cupertino Ca 95014", "Us"], @iso_code="US">
  3. Macker.lookup(mac)
  4. # => #<Macker::Address:0x000000046886d0 @val=161304050786, @name="The Weather Channel", @address=["Mail Stop 500", "Atlanta Ga 30339", "Us"], @iso_code="US">
  5. # More examples
  6. Macker.lookup('64-E6-82-E5-CC-58')
  7. Macker.lookup('64E682E5CC58')
  8. Macker.lookup(110941201353816)
  9. Macker.lookup!(110941201353816)

MAC address

  1. mymac = Macker.lookup('64-E6-82-E5-CC-58')
  2. mymac.class
  3. # => Macker::Address
  4. # Some methods of the address class
  5. mymac.name
  6. mymac.address
  7. mymac.iso_code
  8. mymac.to_i
  9. mymac.to_s
  10. mymac.oui?
  11. mymac.valid?
  12. mymac.broadcast?
  13. mymac.unicast?
  14. mymac.multicast?
  15. mymac.global_uniq?
  16. mymac.local_admin?
  17. mymac.next
  18. mymac.succ
  19. mymac.prefix
  20. mymac.full_address

Cache control

  1. # Update OUI from cache (careful)
  2. Macker.update
  3. # => 2017-07-03 13:03:00 +0200
  4. # Update OUI from remote (straight)
  5. Macker.update(true)
  6. # => 2017-07-03 13:04:00 +0200
  7. # Vendor table with all base16 MAC prefixes as keys
  8. Macker.prefix_table
  9. # => "F8DA0C"=>{:name=>"Hon Hai..."}, ...
  10. # Vendor table with all country iso codes as keys
  11. Macker.iso_code_table
  12. # => "CN"=>[{:name=>"Hon Hai..."} ... ]
  13. # Vendor table with all country vendor names as keys
  14. Macker.vendor_table
  15. # => "Apple, Inc."=>[{:prefix=>...} ... ]
  16. Macker.lapsed!
  17. # => false
  18. Macker.expire!
  19. # => false
  20. Macker.stale!
  21. # => false
  22. Macker.expired?
  23. # => false
  24. Macker.stale?
  25. # => false
  26. Macker.vendors_expiration
  27. # => 2017-07-04 13:04:00 +0200
  28. # Get configuration of Macker
  29. Macker.config
  30. # => #<Macker::Config:0x0000000124ff30 @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