#!/bin/bash # 13/08/2013 #This is dicamarques edition of the script with mac changed to the ones from the list here https://docs.google.com/spreadsheet/lv?key=0AvvH5W4E2lIwdEFCUkxrM085ZGp0UkZlenp6SkJablE and easier wlan config # # wifi_zone_new # A script that emulates a Nintendo Zone in a way that you can actually connect to # other people all over the world. # # Initial version written by Somebunny (9. August 2013). # # # documentation (sort of) # # You will need the following packages/programs: # - rfkill # - dnsmasq (will be killed if already running) # - hostapd (will be killed if already running) # You should not need any additional configuration work. # # This script MUST be run as root, or using sudo, reconfiguring network # interfaces does not seem to work when run by non-root. # # Please adapt the following sections to your own computer: # - variables "zone" and "world", found below # - you can add hotsopts in "InitZone()", just copy what is there # # Usage: call the script with one extra parameter that describes the # MAC address to use. I have prepared some options that work from # the thread in the gbatemp forums. # # Shutdown: call the script with the parameter "stop". # # # A first attempt to organise everything in a somewhat smarter way. # # First, some obligatory checks. if [[ $EUID -ne 0 ]]; then echo "This script must be run as root or with sudo." echo "I don't like this either, but some calls here are really picky!" exit 1 fi # some global settings; you should only need to adapt them for your system once # * this is the network interface used for your custom AP; must be wireless #zone=$2 zone=wlan0 # * this is the network interface used to access the internet; can be almost anything #world=$3 world=eth0 # some local variables; using default values so that something is there ssid="attwifi" mac=4E:53:50:4F:4F:46 country=DE name="Main MAC (All/Any)" # # local function that sets up the local variables; # crude but better than having to change the script every time # NOTE: this part should be heavily modified so that it doesn't # depend on a static config. Maybe something with an external # file or something, so you don't have to share your relay point # with the entire world if you don't want to. # InitZone() { # kill all existing support tools killall dnsmasq 2> /dev/null killall hostapd 2> /dev/null # flush routing entries #iptables --flush # deconfigure network interface /sbin/ifconfig $zone down case $1 in "stop") # emergency exit - restore old network state echo "Stopping Nintendo Zone hotspot" exit ;; "random") #thanks to duke_srg for this. Edit the title line with the games you have. The default has Mk7, Super Mario 3D world and AC:NL #For more codes see https://docs.google.com/spreadsheet/ccc?key=0Ajsweg1Cjr5_dGhlaDNfd2Fid0ZpNTBYQ2pwVUlLT3c#gid=0 just add the ctr code here #everytime you run random it picks a different mac, so once you get mk, then ac... TITLES=AMKAREEGD BASE=NSP RANDOM=$(head -c 2 /dev/urandom | hexdump -e '1/2 "%u"') CTR=$(($RANDOM%$(($(expr length $TITLES)/3)))) mac=$(echo $BASE$TITLES | cut -c 1-3,$(($CTR*3+4))-$(($CTR*3+6)) | hexdump -e '6/1 "%02X:"' | head -c 17) ssid="attwifi" country=DE name="Random MAC from custom title list" ;; "default") # default settings, my old WiFi card that recently died ;; "nash1") ssid="attwifi" mac=00:19:e8:d8:51:e3 country=US name="McDonalds, 6600 Charlotte Pike (3)" ;; "nash2") ssid="attwifi" mac=1C:AF:F7:35:4A:E3 country=US name="Starbucks, 3706 Hillsboro Pike (1)" ;; "nash3") ssid="attwifi" mac=00:0D:67:1C:2C:BD country=US name="McDonalds, 4700 Charlotte Pike (3)" ;; "nash4") ssid="attwifi" mac=00:26:5A:0A:BB:CE country=US name="Starbucks, 4416 Ridgefield Way (1)" ;; "nash5") ssid="attwifi" mac=00:21:d8:de:f8:30 country=US name="Starbucks, 402 21st Avenue South" ;; "nash6") ssid="attwifi" mac=00:22:55:c3:3b:60 country=US name="Starbucks, 424 Church Street (1)" ;; "nash7") ssid="attwifi" mac=88:75:56:6f:da:01 country=US name="Morton's, 618 Church Street" ;; "nash8") ssid="attwifi" mac=1c:af:f7:35:4c:c0 country=US name="Fed-Ex 0752, 212 Broadway (1)" ;; "nash9") ssid="attwifi" mac=00:3a:98:ba:5d:e0 country=US name="Union Station, 1001 Broadway" ;; "nash10") ssid="attwifi" mac=1c:af:f7:35:4c:ac country=US name="Gamestop, 2306 West End Avenue (5)" ;; "nash11") ssid="attwifi" mac=00:3A:9A:7E:74:20 country=US name="Starbucks, 315 4th Ave North (silent)" ;; "nash12") ssid="attwifi" mac=68:BC:0C:F7:EF:31 country=US name="Starbucks, Nashville Airport (4)" ;; "nash13") ssid="attwifi" mac=00:11:93:05:ce:80 country=US name="Opry Mills, North-West Corner (silent)" ;; "nash14") ssid="attwifi" mac=00:0D:67:1C:0C:22 country=US name="McDonalds, 201 Rudy Circle (5)" ;; "nash15") ssid="attwifi" mac=00:0d:67:12:77:4e country=US name="McDonalds, 2806 Gallatin Pike (6)" ;; "nash16") ssid="attwifi" mac=00:0D:67:14:18:6D country=US name="McDonalds, 4114 Hillsboro Pike (2)" ;; "nash17") ssid="attwifi" mac=00 country=US name="" ;; "nj1") ssid="attwifi" mac=00:0f:8f:63:60:20 country=US name="Barnes & Noble, 528 Shoppes Blvd (3)" ;; "nyc1") ssid="attwifi" mac=00:0D:67:15:2D:82 country=US name="Nintendo World NYC 1 (bogus) (6)" ;; "nyc2") ssid="attwifi" mac=00:0D:67:15:D7:21 country=US name="Nintendo World NYC 2 (bogus) (6)" ;; "nyc3") ssid="attwifi" mac=00:0D:67:15:D5:44 country=US name="Nintendo World NYC 3 (bogus) (6)" ;; "acnl") ssid="attwifi" mac=4E:53:50:4F:4F:47 country=US name="Global Spoof (AC:NL)" ;; "pkmn") ssid="attwifi" mac=4E:53:50:4f:4f:45 country=US name="Global Spoof (Pokemon X/Y)" ;; "spoof3") ssid="attwifi" mac=4E:53:50:4F:4F:48 country=DE name="3nd Global Spoof (Fire Emblem / EO4 / SMT4)" ;; "spoof4") ssid="attwifi" mac=4E:53:50:4F:4F:49 country=DE name="4nd Global Spoof (...)" ;; "spoof5") ssid="attwifi" mac=4E:53:50:4F:4F:50 country=DE name="5nd Global Spoof (...)" ;; "spoof6") ssid="attwifi" mac=4E:53:50:4F:4F:51 country=DE name="6nd Global Spoof (...)" ;; "milan") ssid="attwifi" mac=d8:6c:e9:f3:eb:96 country=DE name="DONT UsE THis ONE!" ;; esac } # networkmanager often leaves a lock on the wireless hardware, remove it rfkill unblock wifi # set up parameters InitZone $1 # give our wifi device a static IP address in the correct range so hostapd can associate with it /sbin/ifconfig $zone hw ether $mac /sbin/ifconfig $zone 192.168.23.1 up # start dnsmasq dnsmasq -i $zone --dhcp-range=192.168.23.50,192.168.23.150,255.255.255.0,12h #dnsmasq -i $zone # enable IP forwarding echo 1 > /proc/sys/net/ipv4/ip_forward # set basic routes so that our associated devices can reach the web #iptables --flush #iptables --table nat --flush #iptables --delete-chain #iptables -P INPUT DROP #iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT #iptables -A INPUT -p tcp --dport 22 -j ACCEPT #iptables -A INPUT -i lo -j ACCEPT #iptables --table nat --delete-chain #iptables --table nat --append POSTROUTING --out-interface $world -j MASQUERADE #iptables --append FORWARD --in-interface $zone -j ACCEPT sysctl -w net.ipv4.ip_forward=1 # start hostapd, spawn a temporary file TMPDIR=`mktemp -d` tmpfile=$TMPDIR/nztmp echo $tmpfile trap "rm -rf $TMPDIR" EXIT echo "interface=${zone}" >> $tmpfile echo "driver=nl80211" >> $tmpfile echo "channel=6" >> $tmpfile echo "ssid=${ssid}" >> $tmpfile echo "hw_mode=g" >> $tmpfile echo "auth_algs=1" >> $tmpfile echo "wpa=0" >> $tmpfile echo "country_code=${country}" >> $tmpfile # uncomment the following two lines if you want MAC filtering #echo "macaddr_acl=1" >> $tmpfile #echo "accept_mac_file=/etc/hostapd/macaddr_whitelist" >> $tmpfile echo "Starting Nintendo Zone hotspot, using config ''${name}''" echo "SSID: ${ssid}" echo "Country: ${country}" hostapd $tmpfile -B -dd > /dev/null 2> /dev/null rm -rf $TMPDIR