Guest User

Untitled

a guest
Jun 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. # Spoofs your MAC address, but only while the script is running.
  4. #
  5. # Put your native MAC address at ~/.mac-native in "aa:bb:cc:dd:ee:ff" format.
  6. # Put your Switch's MAC address at ~/.mac-switch in "aa:bb:cc:dd:ee:ff" format.
  7. #
  8. # Run this script with `sudo`. It will change your WiFi MAC address. Kill the
  9. # script and it'll change the MAC address back just before exiting.
  10. #
  11. # Why?
  12. #
  13. # You're on vacation and wanting to play a Switch game in your hotel room. The
  14. # Switch is _supposed_ to handle captive portals properly, but in practice (at
  15. # least for me) it doesn't work most of the time, so if that happens to me:
  16. #
  17. # 1. I open my laptop and run `sudo pretend-to-be-my-switch` in a terminal
  18. # window.
  19. # 2. I join the hotel WiFi network and do the captive portal dance.
  20. # 3. Once I'm connected, I kill the script with Ctrl-C.
  21. # 4. I reattempt connection from the Switch, and this time it should succeed.
  22. #
  23. # If you try to re-join the network from your laptop after killing the script,
  24. # you'll see the captive portal again, because to the network you're an
  25. # entirely new device.
  26. #
  27. # CAVEATS:
  28. #
  29. # * Make sure to look up your native MAC address: `ifconfig en0 | grep ether`
  30. # * If the device you want to spoof isn't en0, you'll have to hack the script.
  31. # * Google suggests that the spoofing only lasts until a reboot, so if the
  32. # script doesn't exit cleanly somehow, a reboot should set your MAC address
  33. # back to normal. Failing that, a clean launch and exit of the script will
  34. # explicitly set your MAC address to the original value.
  35.  
  36. require 'pathname'
  37.  
  38. MAC_SWITCH = Pathname.new(ENV['HOME']).join('.mac-switch').read
  39. MAC_NATIVE = Pathname.new(ENV['HOME']).join('.mac-native').read
  40.  
  41. unless ENV['USER'] == 'root'
  42. STDERR.puts "Must run as root!"
  43. Process.exit!
  44. end
  45.  
  46. def change_mac(mac)
  47. puts "Changing mac address to: #{mac}"
  48. `sudo ifconfig en0 ether #{mac}`
  49. end
  50.  
  51. Signal.trap('INT') do
  52. change_mac(MAC_NATIVE)
  53. Process.exit(0)
  54. end
  55.  
  56. Signal.trap('TERM') do
  57. change_mac(MAC_NATIVE)
  58. Process.exit(0)
  59. end
  60.  
  61. change_mac(MAC_SWITCH)
  62.  
  63. sleep(60) while true
Add Comment
Please, Sign In to add comment