### Manual installation from source Source: https://github.com/acrogenesis/macchanger/blob/main/README.md Clones the repository and installs macchanger from source, bypassing Apple's restrictions. ```bash git clone https://github.com/acrogenesis/macchanger.git cd macchanger sudo make install ``` -------------------------------- ### arm_mac? usage example: choose strategy Source: https://github.com/acrogenesis/macchanger Example usage of the arm_mac? predicate to select between ARM and Intel strategies. ```ruby MacChanger.arm_mac? ? 'ARM strategy' : 'Intel strategy' ``` -------------------------------- ### Example failure path output Source: https://github.com/acrogenesis/macchanger Illustrates the output when the MAC change fails, including the error and troubleshooting tips. ```ruby MacChanger.start(device: 'en0', mac: 'aa:bb:cc:dd:ee:ff') # prints "Setting MAC address to aa:bb:cc:dd:ee:ff..." and, on failure: # "Failed to set MAC address. Make sure you're running with sudo privileges." # "ERROR: This device / interface has no MAC address to set." # plus the TROUBLESHOOTING TIPS block ``` -------------------------------- ### Example usage of change_mac_intel_method Source: https://github.com/acrogenesis/macchanger Shows how to call the method and handle a failure by printing a warning. ```ruby unless MacChanger.change_mac_intel_method('en1', 'aa:bb:cc:dd:ee:ff') warn 'MAC change reported failure' end ``` -------------------------------- ### Example call with failure handling Source: https://github.com/acrogenesis/macchanger Shows how to invoke change_mac_arm_method and handle failure. The method returns true on success, false on failure; on failure it prints 'Failed to set MAC address. Make sure you're running with sudo privileges.' and returns false. ```ruby if MacChanger.change_mac_arm_method('en0', 'aa:bb:cc:dd:ee:ff') puts "new MAC: #{MacChanger.show('en0')}" else puts 'change failed — re-run with sudo privileges' end ``` -------------------------------- ### down? usage example with error handling Source: https://github.com/acrogenesis/macchanger Shows how to call `MacChanger.down?` and rescue the `OptionParser::InvalidArgument` exception. The example prints the error message, which would be `Device en0 is down` when the device is down. ```ruby begin MacChanger.down?('en0') rescue OptionParser::InvalidArgument => e puts e.message # => "Device en0 is down" end ``` -------------------------------- ### Verify MAC change with show(device) Source: https://github.com/acrogenesis/macchanger Example usage of `show` to verify a change made by `change_mac_arm_method` / `change_mac_intel_method`. Checks that the returned MAC matches the expected value and prints a confirmation or failure message. ```ruby new_mac = MacChanger.show('en0') if new_mac && new_mac.strip == 'aa:bb:cc:dd:ee:ff' puts "confirmed: #{new_mac}" else puts 'MAC did not stick' end ``` -------------------------------- ### get_cpu_architecture usage example Source: https://github.com/acrogenesis/macchanger Shows how to call `MacChanger.get_cpu_architecture` and then `MacChanger.arm_mac?`. The comment indicates the expected return value on Apple Silicon. ```ruby arch = MacChanger.get_cpu_architecture # => "arm64" (Apple Silicon) puts MacChanger.arm_mac? # => true ``` -------------------------------- ### start(options) Source: https://github.com/acrogenesis/macchanger Orchestration entry point that decides the strategy, performs the MAC change, and reports the outcome. It generates a random MAC if requested, selects the appropriate method based on CPU architecture, and prints troubleshooting tips on failure. Returns nil; the outcome is communicated via stdout messages. ```APIDOC ## start(options) ### Description Orchestration entry point that decides the strategy, performs the MAC change, and reports the outcome. It generates a random MAC if requested, selects the appropriate method based on CPU architecture, and prints troubleshooting tips on failure. Returns nil; the outcome is communicated via stdout messages. ### Method Function call ### Signature ```ruby def self.start(options) ``` ### Parameters - **options** (Hash with symbol keys) - Required - Runtime options; see configuration.md for full key shape. Keys read: `:random` (truthy ⇒ a MAC is generated with `generate` and written back over `:mac` as a side effect), `:mac`, `:device`. ### Behavior 1. If `options[:random]` is truthy, `options[:mac]` is replaced with `MacChanger.generate`. 2. `MacChanger.arm_mac?` selects `change_mac_arm_method` on Apple Silicon, otherwise `change_mac_intel_method`. 3. On `false` from the change method, prints `ERROR: This device / interface has no MAC address to set.` followed by three troubleshooting tips. ### Return `nil` — the method's last expression is the `unless success` block; meaningful outcome is communicated via stdout messages and the `success` local only. The driver ignores the return value. ### Throws None directly. `generate` never raises; the change methods never raise; validation is the caller's responsibility (the driver calls `valid?` before `start`). ### Request Example ```ruby options = { device: 'en0', random: true } MacChanger.start(options) # prints info + progress, then the new MAC flow puts "generated MAC used: #{options[:mac]}" ``` ### Response Example ```ruby MacChanger.start(device: 'en0', mac: 'aa:bb:cc:dd:ee:ff') # prints "Setting MAC address to aa:bb:cc:dd:ee:ff..." and, on failure: # "Failed to set MAC address. Make sure you're running with sudo privileges." # "ERROR: This device / interface has no MAC address to set." # plus the TROUBLESHOOTING TIPS block ``` ``` -------------------------------- ### start method implementation Source: https://github.com/acrogenesis/macchanger Orchestrates the MAC change: generates a random MAC if requested, selects the method based on CPU architecture, and prints troubleshooting tips on failure. Returns nil. ```ruby def self.start(options) if options[:random] options[:mac] = generate end # Use different methods based on CPU architecture if arm_mac? success = change_mac_arm_method(options[:device], options[:mac]) else success = change_mac_intel_method(options[:device], options[:mac]) end unless success puts "ERROR: This device / interface has no MAC address to set." puts "" puts "TROUBLESHOOTING TIPS:" puts "1. Make sure you're running with sudo privileges" puts "2. Try running the command again" puts "3. Some MAC addresses may be rejected by the system" end end ``` -------------------------------- ### Example invocation for random mode Source: https://github.com/acrogenesis/macchanger Shows the exact call the CLI driver performs for random mode, including printing the generated MAC. ```ruby options = { device: 'en0', random: true } MacChanger.start(options) # prints info + progress, then the new MAC flow puts "generated MAC used: #{options[:mac]}" ``` -------------------------------- ### get_interface_type usage example: handle interface type Source: https://github.com/acrogenesis/macchanger Example usage of get_interface_type to branch on the interface type, with a fallback for unknown types. ```ruby case MacChanger.get_interface_type('en0') when 'Wi-Fi' then 'toggles airport power during changes' when 'Ethernet' then 'direct change only' else puts 'proceeding with direct ifconfig change' end ``` -------------------------------- ### Manual uninstall Source: https://github.com/acrogenesis/macchanger/blob/main/README.md Removes macchanger installed from source. ```bash sudo make uninstall ``` -------------------------------- ### Example error handling for MacChanger.valid? Source: https://github.com/acrogenesis/macchanger Demonstrates rescuing OptionParser::InvalidArgument when valid? is called with an invalid MAC address, printing the error message. ```ruby begin MacChanger.valid?('zz:bb:cc:dd:ee:ff') rescue OptionParser::InvalidArgument => e puts e.message # => "Mac address is not valid" end ``` -------------------------------- ### Example usage of MacChanger.generate and valid? Source: https://github.com/acrogenesis/macchanger Shows calling generate to produce a MAC address and then passing it to valid?, which returns nil for generate output. ```ruby mac = MacChanger.generate # => e.g. "8e:3f:a1:0b:57:cc" MacChanger.valid?(mac) # => nil (never raises for generate output) ``` -------------------------------- ### show(device) — get current MAC address Source: https://github.com/acrogenesis/macchanger Returns the current MAC address of a network interface by running `/sbin/ifconfig |grep ether` and slicing a 17-character substring from offset 7. Returns `nil` when the interface has no matching `ether` line. Failing commands surface as a `nil` return, not an exception. ```ruby def self.show(device) show = `/sbin/ifconfig #{device} |grep ether` show[7, 17] if show end ``` -------------------------------- ### macchanger command-line usage Source: https://github.com/acrogenesis/macchanger/blob/main/README.md Shows the full command-line help for macchanger, listing all options and their descriptions. ```bash Usage: macchanger [options] device -v, --version Displays MacChanger version -m, --mac MAC Set the MAC address, macchanger -m XX:XX:XX:XX:XX:XX en0 -r, --random Set random MAC address, macchanger -r en0 -s, --show Show the MAC address, macchanger -s en0 --enable-private Enable private Wi-Fi addresses (macOS Sequoia+ feature) --disable-private Disable private Wi-Fi addresses (use real MAC) --status Show private Wi-Fi address status for all networks ``` -------------------------------- ### Basic macchanger invocations Source: https://github.com/acrogenesis/macchanger Shows common usage: display current MAC with -s, set a specific MAC with -m, set a random unicast MAC with -r, and print version with -v. Requires sudo for operations on a network interface. ```bash sudo macchanger -s en0 # show current MAC sudo macchanger -m aa:bb:cc:dd:ee:ff en0 # set a specific MAC sudo macchanger -r en0 # set a random unicast MAC macchanger -v # "Version: 1.6.1" ``` -------------------------------- ### macchanger error invocations Source: https://github.com/acrogenesis/macchanger Each command prints the specified error message followed by the full usage banner and exits with status 0. Covers missing arguments, invalid MAC, missing device, and unknown flag. ```bash macchanger # prints "device" + usage (MissingArgument) macchanger -s # prints "device" + usage (MissingArgument) macchanger en0 # prints "MAC address or random option" + usage macchanger -m zz:bb:cc:dd:ee:ff en0 # prints "Mac address is not valid" + usage macchanger -m aa:bb:cc:dd:ee:ff # prints "device" + usage (MissingArgument) macchanger --bogus en0 # optparse's invalid option error + usage ``` -------------------------------- ### Command-line invocations that trigger errors Source: https://github.com/acrogenesis/macchanger Shows the exact commands that produce each error condition, with the resulting error message in a comment. Useful for testing error handling. ```bash macchanger # -> "device" (MissingArgument) ``` ```bash macchanger -s # -> "device" (MissingArgument) ``` ```bash macchanger en0 # -> "MAC address or random option" (InvalidOption) ``` ```bash macchanger -m badmac en0 # -> "Mac address is not valid" (InvalidArgument) ``` ```bash macchanger -m aa:bb:cc:dd:ee en0 # -> "Mac address is not valid" (5 octets, regex requires 6) ``` ```bash macchanger --bogus en0 # -> optparse: "invalid option: --bogus" ``` ```bash macchanger -m # -> optparse: "missing argument: -m" ``` -------------------------------- ### down? method implementation Source: https://github.com/acrogenesis/macchanger Defines the class method `down?` that checks if a network interface is down by running `/sbin/ifconfig -d` and grepping for the device name. Raises `OptionParser::InvalidArgument` with message `Device is down` if the interface is listed. Note that the device name is interpolated into a regex, so regex metacharacters in the device name would be interpreted; an unknown device passes the check. ```ruby def self.down?(device) unless `/sbin/ifconfig -d |grep -E '^#{device}:'`.empty? fail OptionParser::InvalidArgument, "Device #{device} is down" end end ``` -------------------------------- ### down?(device) Source: https://github.com/acrogenesis/macchanger Verifies that a network interface is not down. Raises an OptionParser::InvalidArgument error if the device is listed as down. ```APIDOC ## down?(device) ### Description Verifies that an interface is not listed as *down*; raises on failure. ### Method `down?` (class method) ### Parameters #### Path Parameters - **device** (String) - Required - Network interface name, e.g. `en0` ### Response #### Success Response - Returns `nil` when the device is not present in `ifconfig -d` output. #### Error Response - **OptionParser::InvalidArgument** - Thrown when `ifconfig -d` lists the interface (the listing lines begin with the device name followed by `:`). Message: `Device is down`. ### Request Example ```ruby begin MacChanger.down?('en0') rescue OptionParser::InvalidArgument => e puts e.message # => "Device en0 is down" end ``` ``` -------------------------------- ### Catching errors from MacChanger class methods Source: https://github.com/acrogenesis/macchanger Shows how to catch the same error conditions when calling MacChanger class methods directly, with the expected message. ```ruby begin MacChanger.valid?('not-a-mac') rescue OptionParser::InvalidArgument => e e.message # => "Mac address is not valid" end ``` ```ruby begin MacChanger.down?('en0') rescue OptionParser::InvalidArgument => e e.message # => "Device en0 is down" end ``` -------------------------------- ### get_interface_type(device) Source: https://github.com/acrogenesis/macchanger Classifies an interface by querying `networksetup -listallhardwareports`. Returns a string indicating whether the device is Wi-Fi, Ethernet, or Unknown. ```APIDOC ## get_interface_type(device) ### Description Classifies an interface by querying `networksetup -listallhardwareports`. Returns a string indicating whether the device is Wi-Fi, Ethernet, or Unknown. ### Method `get_interface_type(device)` (class method) ### Parameters - **device** (String) - Required - Network interface name, e.g. `en0`. ### Return Value - **String** - One of the literal values: - `"Wi-Fi"` - The device name appears in the hardware port whose header line contains `Wi-Fi`. - `"Ethernet"` - The device name appears in the hardware port whose header line contains `Ethernet`. - `"Unknown"` - No match in either block. ### Example ```ruby case MacChanger.get_interface_type('en0') when 'Wi-Fi' then 'toggles airport power during changes' when 'Ethernet' then 'direct change only' else puts 'proceeding with direct ifconfig change' end ``` ``` -------------------------------- ### get_cpu_architecture method implementation Source: https://github.com/acrogenesis/macchanger Defines the class method `get_cpu_architecture` that returns the stripped output of `uname -m`. On Apple Silicon this is `arm64`, on Intel Macs typically `x86_64`. ```ruby def self.get_cpu_architecture arch_output = `uname -m`.strip return arch_output end ``` -------------------------------- ### change_mac_intel_method(device, mac) Source: https://github.com/acrogenesis/macchanger Changes the MAC address on Intel hosts and verifies the result. It prints an info message about the interface type, disassociates from any network for Wi-Fi interfaces, and sets the MAC address using ifconfig for other types. Returns true if the read-back MAC matches the target, false otherwise. ```APIDOC ## change_mac_intel_method(device, mac) ### Description Changes the MAC address on Intel hosts and verifies the result. It prints an info message about the interface type, disassociates from any network for Wi-Fi interfaces, and sets the MAC address using ifconfig for other types. Returns true if the read-back MAC matches the target, false otherwise. ### Method Function call ### Signature ```ruby def self.change_mac_intel_method(device, mac) ``` ### Parameters - **device** (String) - Required - Network interface name, e.g. `en0` - **mac** (String) - Required - Target MAC address (six colon-separated hex octets) ### Behavior - Always prints `INFO: Type of interface is . Will disassociate from any network.` - **Wi-Fi**: prints deprecation warning for `airport` CLI, then disassociates via `sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z` followed by `sleep 2`. - **All other types**: direct `sudo /sbin/ifconfig ether `. ### Verification Read back with `show(device)`, `strip`, compare to `mac`. ### Return - `true` when the read-back MAC matches; `false` otherwise, printing `Failed to set MAC address. Make sure you're running with sudo privileges.` ### Throws None. ### Request Example ```ruby unless MacChanger.change_mac_intel_method('en1', 'aa:bb:cc:dd:ee:ff') warn 'MAC change reported failure' end ``` ``` -------------------------------- ### change_mac_intel_method signature Source: https://github.com/acrogenesis/macchanger Defines the method that changes the MAC address on Intel hosts. It prints an info message, disassociates from the network (Wi-Fi uses the deprecated airport CLI, others use ifconfig), then verifies by reading back the MAC. Returns true on success, false on failure with a sudo warning. ```ruby def self.change_mac_intel_method(device, mac) ``` -------------------------------- ### arm_mac? predicate: check for ARM64 architecture Source: https://github.com/acrogenesis/macchanger Returns true when the CPU architecture is exactly arm64, false otherwise. Used to decide which change strategy to apply. ```ruby def self.arm_mac? arch = get_cpu_architecture return arch == "arm64" end ``` -------------------------------- ### valid?(mac) Source: https://github.com/acrogenesis/macchanger Validates a MAC address string; raises on failure. Returns nil when the MAC matches the required format. ```APIDOC ## valid?(mac) ### Description Validates a MAC address string; raises on failure. Returns `nil` when the MAC matches the required format. ### Method `MacChanger.valid?(mac)` ### Parameters - **mac** (String) - Required - MAC address to validate, e.g. `aa:bb:cc:dd:ee:ff` ### Return `nil` when the MAC matches. The method has no explicit return value on the success path. ### Throws `OptionParser::InvalidArgument` with message `Mac address is not valid` when `mac` does not match the anchor regex `^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$`. The regex requires exactly six colon-separated hex octets with no whitespace, no leading/trailing characters, and no other separators (`-` or Cisco-style `xxxx.xxxx.xxxx` forms fail). Calling it with `nil` raises `NoMethodError` (the driver only calls it when a MAC was supplied via `-m`). ### Request Example ```ruby begin MacChanger.valid?('zz:bb:cc:dd:ee:ff') rescue OptionParser::InvalidArgument => e puts e.message # => "Mac address is not valid" end ``` ``` -------------------------------- ### arm_mac? Source: https://github.com/acrogenesis/macchanger Convenience predicate that decides which change strategy to use. Returns true when the CPU architecture is arm64, false otherwise. ```APIDOC ## arm_mac? ### Description Convenience predicate that decides which change strategy to use. Returns `true` when `uname -m` equals exactly `arm64`, `false` otherwise. ### Method `arm_mac?` (class method) ### Parameters None ### Return Value - **Boolean** - `true` if the CPU architecture is `arm64`, `false` otherwise. ### Example ```ruby MacChanger.arm_mac? ? 'ARM strategy' : 'Intel strategy' ``` ``` -------------------------------- ### get_cpu_architecture Source: https://github.com/acrogenesis/macchanger Returns the CPU architecture reported by `uname -m`. Useful for determining if the system is ARM-based (Apple Silicon) or Intel. ```APIDOC ## get_cpu_architecture ### Description Returns the CPU architecture reported by `uname -m`. ### Method `get_cpu_architecture` (class method) ### Parameters None ### Response #### Success Response - **String** - The stripped output of `uname -m`; on Apple Silicon this is `arm64`, on Intel Macs typically `x86_64`. ### Request Example ```ruby arch = MacChanger.get_cpu_architecture # => "arm64" (Apple Silicon) puts MacChanger.arm_mac? # => true ``` ``` -------------------------------- ### change_mac_arm_method(device, mac) Source: https://github.com/acrogenesis/macchanger Changes the MAC address on Apple Silicon (arm64) hosts and verifies the result. It handles Wi-Fi interfaces by cycling airport power and applies the change via ifconfig, then reads back the MAC to confirm success. ```APIDOC ## change_mac_arm_method(device, mac) ### Description Changes the MAC address on Apple Silicon (`arm64`) hosts and verifies the result. It handles Wi-Fi interfaces by cycling airport power and applies the change via ifconfig, then reads back the MAC to confirm success. ### Method `change_mac_arm_method` (class method) ### Parameters - **device** (String) - Required - Network interface name, e.g. `en0` - **mac** (String) - Required - Target MAC address (six colon-separated hex octets) ### Behavior - **Wi-Fi**: Prints `INFO: Type of interface is Wi-Fi. Will disassociate from any network.`, cycles airport power via `sudo /usr/sbin/networksetup -setairportpower off` → `sleep 2` → `... on` → `sleep 2`, runs `sudo /sbin/ifconfig ether `, runs `sudo /usr/sbin/networksetup -detectnewhardware`, `sleep 2`, then verifies. - **All other types** (Ethernet, Unknown): Skips the Wi-Fi power cycle and applies `sudo /sbin/ifconfig ether ` directly. ### Verification The new value is read back with `show(device)` and compared (with `strip`) to `mac`. All commands are shelled through `system`, so failure is a `false` (non-zero) exit from the underlying command, captured in the `success` local. ### Return `true` when the read-back MAC equals the requested `mac`; `false` otherwise. ### Throws None. On any failure the method prints `Failed to set MAC address. Make sure you're running with sudo privileges.` and returns `false`. ### Notes Because the method shells out to `sudo` for every privileged command, it must be invoked from a context that can elevate (e.g. an interactive sudo session), and shell command strings are interpolated from `device` and `mac` without escaping. ### Request Example ```ruby if MacChanger.change_mac_arm_method('en0', 'aa:bb:cc:dd:ee:ff') puts "new MAC: #{MacChanger.show('en0')}" else puts 'change failed — re-run with sudo privileges' end ``` ``` -------------------------------- ### Rescue block for optparse errors Source: https://github.com/acrogenesis/macchanger The script rescues all three optparse error classes together at the top level and prints the error message plus the usage banner. ```ruby rescue OptionParser::InvalidArgument, OptionParser::MissingArgument, OptionParser::InvalidOption => error puts error puts optparse end ``` -------------------------------- ### get_interface_type(device): classify interface as Wi-Fi, Ethernet, or Unknown Source: https://github.com/acrogenesis/macchanger Classifies a network interface by querying networksetup -listallhardwareports. Returns "Wi-Fi" if the device appears in the Wi-Fi hardware port block, "Ethernet" if in the Ethernet block, otherwise "Unknown". ```ruby def self.get_interface_type(device) # Check if it's Wi-Fi interface wifi_check = `networksetup -listallhardwareports | grep -A1 "Wi-Fi" | grep "#{device}"` return "Wi-Fi" unless wifi_check.empty? # Check if it's Ethernet ethernet_check = `networksetup -listallhardwareports | grep -A1 "Ethernet" | grep "#{device}"` return "Ethernet" unless ethernet_check.empty? return "Unknown" end ``` -------------------------------- ### Method signature: change_mac_arm_method(device, mac) Source: https://github.com/acrogenesis/macchanger Defines the class method that changes the MAC address on Apple Silicon (arm64) hosts. It branches on interface type: for Wi-Fi it cycles airport power and applies the MAC; for other types it applies the MAC directly. Returns true if the read-back MAC matches the requested one, false otherwise. ```ruby def self.change_mac_arm_method(device, mac) ``` -------------------------------- ### generate Source: https://github.com/acrogenesis/macchanger Generates a random, unicast MAC address. The least significant bit of the most significant octet is masked off to guarantee the unicast bit is 0. ```APIDOC ## generate ### Description Generates a random, **unicast** MAC address. The least significant bit of the most significant octet is masked off (`rand(256) & ~1`), guaranteeing the unicast bit is 0; the remaining five octets are uniform `rand(256)` draws. ### Method `MacChanger.generate` ### Parameters None. ### Return `String` — six colon-separated lowercase hex octets (`xx:xx:xx:xx:xx:xx`). ### Request Example ```ruby mac = MacChanger.generate # => e.g. "8e:3f:a1:0b:57:cc" MacChanger.valid?(mac) # => nil (never raises for generate output) ``` ``` -------------------------------- ### Validate a MAC address string Source: https://github.com/acrogenesis/macchanger Raises OptionParser::InvalidArgument with message 'Mac address is not valid' when the input does not match the anchor regex. Returns nil on success. The regex requires exactly six colon-separated hex octets with no whitespace or other separators; calling with nil raises NoMethodError. ```ruby def self.valid?(mac) unless mac.match(/^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/) fail OptionParser::InvalidArgument, 'Mac address is not valid' end end ``` -------------------------------- ### Generate a random unicast MAC address Source: https://github.com/acrogenesis/macchanger Returns a string of six colon-separated lowercase hex octets. The least significant bit of the most significant octet is masked off to guarantee the unicast bit is 0; the remaining five octets are uniform random draws. ```ruby def self.generate # least significant bit of most significant octet has to be 0 to to be unicast [format('%0.2x', rand(256) & ~1), (1..5).map { format('%0.2x', rand(256)) }].join(':') end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.