Skip to content

Instantly share code, notes, and snippets.

@TJRoger
Created December 5, 2016 07:08
Show Gist options
  • Save TJRoger/f8692a511918801e0e5cdf3c2ccb912f to your computer and use it in GitHub Desktop.
Save TJRoger/f8692a511918801e0e5cdf3c2ccb912f to your computer and use it in GitHub Desktop.
#!/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