Tag: set all

Proxy Setting for all network devices

An issue that came up recently was the proxy URL and bypass was not being set correctly when connecting a Mac via USB-A or USB-C cable to a network enabled device, like screen, docks or hubs. DisplayLink was installed so they were all making a network connection but as no proxy was set there were a few access issues.

In the past setting network settings via a script had been pretty easy but now Mac’s don’t have a network port and desks are ¬†switching to a single cable solution which is USB-C to a dock which than connects to screens, ethernet and power its got a little harder.

The previous solution was to identify the device and add the settings, for example if it was an ethernet connection then you just specify the connection and the details:

1
2
networksetup -setautoproxyurl "Ethernet" http://urltoyourproxy.pac
networksetup -setproxybypassdomains "Ethernet" "*.local" "169.254/16" "*.adomain.com"

You could add this for various devices that were used to connect to a network:

1
2
3
4
networksetup -setautoproxyurl "Apple USB Ethernet Adapter"
networksetup -setautoproxyurl "Wi-Fi"
networksetup -setautoproxyurl "Thunderbolt Ethernet"
networksetup -setautoproxyurl "USB Ethernet"

The problem was with docks and hubs and screens all being different names and makes and models there  you would have to set each item specifically:

1
networksetup -setautoproxyurl "Philips 231P4U"

Clearly this is not ideal as usually as an Admin you have no idea what is being put on a desk, so another solution was required.

The following script is via a variation from MacMule, this loops through all the devices that have been connected or are connected and regardless of name adds in the required details.

Simply set you values at the top of the script. The script can then be deployed via MDM such as JAMF and set it to run on network change. Now when a Mac changes network connection the script loops through and adds in the the correct proxy URL and proxy bypass details.

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
####################################################################################################
#
# More information: https://macmule.com/2014/12/07/how-to-change-the-automatic-proxy-configuration-url-in-system-preferences-via-a-script/
#
# GitRepo: https://github.com/macmule/setAutomaticProxyConfigurationURL
#
# License: http://macmule.com/license/
#
# Updated to add proxyBypass settings by M Griffin October 2017
####################################################################################################

# HARDCODED VALUES ARE SET HERE
autoProxyURL="http://urltoyourproxy.pac"
proxyBypassDomains="*.local 169.254/16 *.adomain.com"

# CHECK TO SEE IF A VALUE WAS PASSED FOR $4, AND IF SO, ASSIGN IT
if [ "$4" != "" ] && [ "$autoProxyURL" == "" ]; then
autoProxyURL=$4
fi

# Detects all network hardware & creates services for all installed network hardware
/usr/sbin/networksetup -detectnewhardware

IFS=$'\n'

#Loops through the list of network services
for i in $(networksetup -listallnetworkservices | tail +2 );
do

# Get a list of all services
proxyBypassDomainsLocal=`/usr/sbin/networksetup -getproxybypassdomains "$i" | head -1 | cut -c 6-`

# Echo's the name of any matching services & the autoproxyURL's set
echo "$i Proxy set to $proxyBypassDomainsLocal"

# If the value returned of $autoProxyURLLocal does not match the value of $autoProxyURL for the interface $i, change it.
if [[ $proxyBypassDomainsLocal != $proxyBypassDomains ]]; then
/usr/sbin/networksetup -setproxybypassdomains $i $proxyBypassDomains
echo "Set proxy bypass for $i to $proxyBypassDomains"
fi

if [[ $autoProxyURLLocal != $autoProxyURL ]]; then
/usr/sbin/networksetup -setautoproxyurl $i $autoProxyURL
echo "Set auto proxy for $i to $autoProxyURL"
fi
# Enable auto proxy once set
/usr/sbin/networksetup -setautoproxystate "$i" on
echo "Turned on auto proxy for $i"

done

unset IFS

# Echo that we're done
echo "Auto proxy present, correct & enabled for all interfaces"

Recent Posts

Recent Comments

    Archives

    Categories

    Meta

    GiottoPress by Enrique Chavez