Created
December 5, 2016 07:08
-
-
Save TJRoger/f8692a511918801e0e5cdf3c2ccb912f 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 | |
PAC="http://192.168.3.2/proxy.pac" | |
function networkService() { | |
services=$(networksetup -listnetworkserviceorder | grep 'Hardware Port') | |
while read line; do | |
sname=$(echo $line | awk -F "(, )|(: )|[)]" '{print $2}') | |
sdev=$(echo $line | awk -F "(, )|(: )|[)]" '{print $4}') | |
#echo "Current service: $sname, $sdev, $currentservice" | |
if [ -n "$sdev" ]; then | |
ifconfig $sdev 2>/dev/null | grep 'status: active' > /dev/null 2>&1 | |
rc="$?" | |
if [ "$rc" -eq 0 ]; then | |
currentservice="$sname" | |
break | |
fi | |
fi | |
done <<< "$(echo "$services")" | |
if [ -n $currentservice ]; then | |
echo $currentservice | |
else | |
echo false | |
fi | |
} | |
service=$(networkService) | |
state=$(networksetup -getautoproxyurl $service |grep Enabled |awk -F "(, )|(: )|[)]" '{print $2}') | |
if [ "$state" = "Yes" ]; then | |
networksetup -setautoproxystate $service off | |
echo "turned auto proxy off" | |
else | |
networksetup -setautoproxyurl $service $PAC | |
echo "set autoproxy url of $service to $PAC " | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment