-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathremoveSSID.sh
executable file
·35 lines (30 loc) · 1.18 KB
/
removeSSID.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
#
# Check if an SSID exists and delete it if it does.
# Change the wifinetwork variable to the name of your SSID.
# Turn Wi-Fi off and on in order to disconnect from the removed network.
#
wifiInterface=$(networksetup -listallhardwareports | /usr/bin/awk '/Wi-Fi|AirPort/ {getline; print $NF}')
wifiNetwork="Contoso Inc"
activeWiFiNetwork=$(networksetup -getairportnetwork $wifiInterface | cut -c 24-)
searchResult=$(networksetup -listpreferredwirelessnetworks $wifiInterface | grep "$wifiNetwork")
# Search for it
# Depending on your needs you may have nothing else to do, uncomment line 18 if so
if [ "$searchResult" = "" ]; then
echo "No saved $wifiNetwork found"
# exit 0
else
echo "$wifiNetwork found as a saved network. Removing.."
networksetup -removepreferredwirelessnetwork $wifiInterface "$wifiNetwork"
fi
# Check active SSID
if [ "$activeWiFiNetwork" != "$wifiNetwork" ]; then
echo "Not currently connected to $wifiNetwork"
exit 0
else
echo "$wifiNetwork found as an active network, power cycling..."
fi
# Power cycle Wi-Fi so network is disconnected
networksetup -setairportpower $wifiInterface off
sleep 0.5
networksetup -setairportpower $wifiInterface on