Last active
January 7, 2016 11:48
-
-
Save jsleeio/dcb71eef6cd0f2632c83 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# John Slee <[email protected]> | |
keep_until="heart of gold" | |
get_wifi_interface() { | |
networksetup -listallhardwareports | sed -n '/Wi-Fi$/,/^Device/ { s/.*\(en[0-9]\)$/\1/p; }' | |
} | |
get_wifi_ssids() { | |
IFS="\\012" networksetup -listpreferredwirelessnetworks $1 \ | |
| sed -n "1,/$2/d; s/^[[:space:]]*//; p" | |
} | |
if=$(get_wifi_interface | head -1) | |
# quick sanity check | |
if ! /sbin/ifconfig $if > /dev/null 2>&1 ; then | |
echo "can't find your wifi, halp" | |
exit 1 | |
fi | |
if [ "$1" == "no-really" ] ; then | |
really=1 | |
else | |
echo "Dry-run. Pass 'no-really' on the commandline to actually remove SSIDs." | |
echo | |
fi | |
get_wifi_ssids "$if" "$keep_until" | while read ssid ; do | |
if [ "$really" == 1 ] ; then | |
sudo networksetup -removepreferredwirelessnetwork "$if" "$ssid" | |
else | |
echo "Found unwanted SSID: $ssid" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably need to check that en0 is your wireless interface (mine's en1) :) It'll just have a whine if it's not.