├── LICENSE ├── Makefile ├── README.md └── bin └── macchanger /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Adrián Rangel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX = /usr/local 2 | BIN = macchanger 3 | 4 | install: 5 | cp -f bin/$(BIN) $(PREFIX)/bin/$(BIN) 6 | 7 | uninstall: 8 | rm -f $(PREFIX)/bin/$(BIN) 9 | 10 | .PHONY: install uninstall 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | macchanger 2 | ========== 3 | 4 | ![](https://acrogenesis.com/macchanger/preview.png) 5 | 6 | Easily change your mac address, for OS X 7 | 8 | Usage 9 | --- 10 | 11 | ``` 12 | Usage: macchanger [options] device 13 | -m, --mac MAC Set the MAC address, macchanger -m XX:XX:XX:XX:XX:XX en0 14 | -r, --random Set random MAC address, macchanger -r en0 15 | -s, --show Show the MAC address, macchanger -s en0 16 | 17 | ``` 18 | 19 | Install 20 | --- 21 | 22 | 1. Install brew (http://brew.sh/) 23 | 2. `brew update` 24 | 3. `brew install acrogenesis/macchanger/macchanger` 25 | 26 | Contributing 27 | --- 28 | 29 | 1. Fork it. 30 | 2. Create a branch `git checkout -b my_markup` 31 | 3. Commit your changes `git commit -am "Cool new feature"` 32 | 4. Push to the branch `git push origin my_markup` 33 | 5. Open a [Pull Request][1] 34 | 6. Enjoy a refreshing `Insert Favorite Beverage` and wait 35 | 36 | [1]: https://github.com/acrogenesis/macchanger/pulls 37 | -------------------------------------------------------------------------------- /bin/macchanger: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'optparse' 4 | options = {} 5 | VERSION = '1.4.1' 6 | 7 | optparse = OptionParser.new do |opts| 8 | opts.banner = 'Usage: macchanger [options] device' 9 | 10 | opts.on('-v', '--version', 'Displays MacChanger version') do 11 | puts "Version: #{VERSION}" 12 | exit 13 | end 14 | 15 | opts.on('-m', '--mac MAC', 'Set the MAC address, macchanger -m XX:XX:XX:XX:XX:XX en0') do |m| 16 | options[:mac] = m.downcase 17 | puts m 18 | end 19 | 20 | opts.on('-r', '--random', 'Set random MAC address, macchanger -r en0') do |r| 21 | options[:random] = r 22 | end 23 | 24 | opts.on('-s', '--show', 'Show the MAC address, macchanger -s en0') do |s| 25 | options[:show] = s 26 | end 27 | end 28 | 29 | class MacChanger 30 | def self.show(device) 31 | show = `/sbin/ifconfig #{device} |grep ether` 32 | show[7, 17] 33 | end 34 | 35 | def self.generate 36 | # least significant bit of most significant octet has to be 0 to to be unicast 37 | [format('%0.2x', rand(256) & ~1), (1..5).map { format('%0.2x', rand(256)) }].join(':') 38 | end 39 | 40 | def self.valid?(mac) 41 | unless mac.match(/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/) 42 | fail OptionParser::InvalidArgument, 'Mac address is not valid' 43 | end 44 | end 45 | 46 | def self.down?(device) 47 | unless `/sbin/ifconfig -d |grep -E '^#{device}:'`.empty? 48 | fail OptionParser::InvalidArgument, "Device #{device} is down" 49 | end 50 | end 51 | 52 | def self.random(options) 53 | options[:mac] = generate 54 | if set(options) 55 | puts "Successfully setup #{options[:mac]} on #{options[:device]} device" 56 | else 57 | random(options) 58 | end 59 | end 60 | 61 | def self.set(options) 62 | if system("sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport #{options[:device]} -z") 63 | if system("sudo /sbin/ifconfig #{options[:device]} ether #{options[:mac]}") 64 | show(options[:device]) == options[:mac] 65 | end 66 | else 67 | puts "Can't desaccociate #{options[:device]} WiFi, manually disconnect it and try again" 68 | end 69 | end 70 | 71 | def self.start(options) 72 | if options[:random] 73 | random(options) 74 | else 75 | if set(options) 76 | puts "Successfully setup #{options[:mac]} on #{options[:device]} device" 77 | else 78 | puts 'Try another mac address' 79 | end 80 | end 81 | end 82 | end 83 | 84 | begin 85 | optparse.parse! 86 | options[:device] = ARGV[0] or fail OptionParser::MissingArgument, 'device' 87 | MacChanger.down?(options[:device]) 88 | 89 | if options[:show] 90 | puts "Your mac address is: #{MacChanger.show(options[:device])}" 91 | else 92 | fail OptionParser::InvalidOption, 'MAC address or random option' if options[:mac].nil? && options[:random].nil? 93 | MacChanger.valid?(options[:mac]) unless options[:random] 94 | MacChanger.start(options) 95 | end 96 | rescue OptionParser::InvalidArgument, OptionParser::MissingArgument, OptionParser::InvalidOption => error 97 | puts error 98 | puts optparse 99 | end 100 | --------------------------------------------------------------------------------