Last active
October 27, 2020 02:59
-
-
Save talkingmoose/455a5b2db52991223972572c5051f74a to your computer and use it in GitHub Desktop.
The script will disable any proxy server first. Then it will use ping to test connectivity to the proxy server for up to two minutes. If unable to reach the proxy server, it does nothing more. If the device gets a reponse from the ping, it will set the auto proxy URL and enable. Use this with a Jamf policy triggered by Network State Change and e…
This file contains hidden or 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/sh | |
# enter the DNS or IP address of the network proxy | |
proxyAddress="proxy.domain.com" | |
# create a list of all Wi-Fi and Ethernet services | |
interfaces=$( networksetup -listallnetworkservices | egrep "Wi-Fi|Ethernet" ) | |
# always turn of proxy configuration first for each network interface | |
while IFS= read anInterface | |
do | |
networksetup -setautoproxystate "$anInterface" off | |
done <<< "$interfaces" | |
# attempt to ping the proxy for up to two minutes | |
for i in {1..120} # for 120 seconds | |
do | |
ping -c1 "$proxyAddress" && break # attempt to ping the proxy | |
sleep 1 | |
done | |
# make one last attempt to ping and get result | |
ping -c1 "$proxyAddress" && break # attempt to ping the proxy | |
# if ping reaches the proxy, enable the proxy URL for Wi-Fi and Ethernet interfaces | |
if [ $? = 0 ]; then | |
while IFS= read anInterface | |
do | |
networksetup -setautoproxyurl "$anInterface" "http://$proxyAddress" | |
done <<< "$interfaces" | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment