Created
June 18, 2018 19:35
-
-
Save savetheclocktower/dc4fa167cf65080373b2815b75e3b07d to your computer and use it in GitHub Desktop.
pretend-to-be-my-switch: MAC address spoofing for OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Spoofs your MAC address, but only while the script is running. | |
# | |
# Put your native MAC address at ~/.mac-native in "aa:bb:cc:dd:ee:ff" format. | |
# Put your Switch's MAC address at ~/.mac-switch in "aa:bb:cc:dd:ee:ff" format. | |
# | |
# Run this script with `sudo`. It will change your WiFi MAC address. Kill the | |
# script and it'll change the MAC address back just before exiting. | |
# | |
# Why? | |
# | |
# You're on vacation and wanting to play a Switch game in your hotel room. The | |
# Switch is _supposed_ to handle captive portals properly, but in practice (at | |
# least for me) it doesn't work most of the time, so if that happens to me: | |
# | |
# 1. I open my laptop and run `sudo pretend-to-be-my-switch` in a terminal | |
# window. | |
# 2. I join the hotel WiFi network and do the captive portal dance. | |
# 3. Once I'm connected, I kill the script with Ctrl-C. | |
# 4. I reattempt connection from the Switch, and this time it should succeed. | |
# | |
# If you try to re-join the network from your laptop after killing the script, | |
# you'll see the captive portal again, because to the network you're an | |
# entirely new device. | |
# | |
# CAVEATS: | |
# | |
# * Make sure to look up your native MAC address: `ifconfig en0 | grep ether` | |
# * If the device you want to spoof isn't en0, you'll have to hack the script. | |
# * Google suggests that the spoofing only lasts until a reboot, so if the | |
# script doesn't exit cleanly somehow, a reboot should set your MAC address | |
# back to normal. Failing that, a clean launch and exit of the script will | |
# explicitly set your MAC address to the original value. | |
require 'pathname' | |
MAC_SWITCH = Pathname.new(ENV['HOME']).join('.mac-switch').read | |
MAC_NATIVE = Pathname.new(ENV['HOME']).join('.mac-native').read | |
unless ENV['USER'] == 'root' | |
STDERR.puts "Must run as root!" | |
Process.exit! | |
end | |
def change_mac(mac) | |
puts "Changing mac address to: #{mac}" | |
`sudo ifconfig en0 ether #{mac}` | |
end | |
Signal.trap('INT') do | |
change_mac(MAC_NATIVE) | |
Process.exit(0) | |
end | |
Signal.trap('TERM') do | |
change_mac(MAC_NATIVE) | |
Process.exit(0) | |
end | |
change_mac(MAC_SWITCH) | |
sleep(60) while true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment