ulfben

nintendozone.sh

Nov 29th, 2017
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Clean up, for good measure.
  4. service hostapd stop
  5. killall hostapd
  6.  
  7. #  Make sure that ctrl+c exits our script properly
  8. trap exit SIGINT SIGTERM
  9.  
  10. #  Configs
  11. MAC_FILE=/etc/hostapd/mac_nintendozone  # dataset
  12. STREETPASS_REFRESH=28800                # 8 hours
  13. CONFIG_FILE=/dev/shm/nintendozone.conf  # temporary AP config in RAM
  14.  
  15. # Keep repeating the list of MACs forever
  16. while true ; do
  17.    # The dataset might change so let's calculate within the loop.
  18.    LINE_COUNT=$(wc -l < $MAC_FILE)        
  19.    SLEEP_TIME=$(($STREETPASS_REFRESH/$LINE_COUNT))
  20.    
  21.    #  Loop through each line in random order
  22.    sort -R $MAC_FILE | while read MAC SSID; do
  23.  
  24.       #  Run hostapd with a conf file that we generate on the fly
  25.       #  Do not tab this next section in, or you will have a broken config file  
  26. cat > $CONFIG_FILE <<_EOF_
  27. interface=wlan0
  28. ssid=$SSID
  29. bssid=$MAC
  30. channel=1
  31. #bridge=br0
  32. macaddr_acl=0
  33. #auth_algs=1
  34. ignore_broadcast_ssid=0
  35. wpa=0
  36. driver=rtl871xdrv
  37. ieee80211n=0
  38. wmm_enabled=0
  39. hw_mode=g
  40. device_name=RTL8192CU
  41. manufacturer=Realtek
  42. _EOF_
  43.  
  44.       echo "==========================================="
  45.       echo "SSID:" $SSID " - BSSID:" $MAC
  46.       echo "Time before next change:" $SLEEP_TIME "seconds"
  47.       echo "Current time:" $(date)
  48.       echo "==========================================="
  49.  
  50.       #  Launch the AP with the new settings
  51.       timeout $SLEEP_TIME hostapd $CONFIG_FILE
  52.  
  53.       echo ""
  54.       echo ""
  55.       done
  56.    #  We have looped through the entire dataset. Let's do it again.
  57.    echo "~~~~Looping Back to Beginning~~~~"
  58. done
Add Comment
Please, Sign In to add comment