Using networksetup to set prefs for multiple interfaces

Kedgar
Contributor

Hello,

I'm modifying the setWebProxy.sh script provided by JAMF to instead set a proxy pac file (setautoproxyurl). Anyways, if I want to deploy this I want to set it for all network interfaces at once. Not every computer has the same interface names... is there a way I can programatically set these... or toss it a wildcard that you are aware of?

The syntax is /usr/sbin/networksetup -setautoproxyurl $networkinterface $proxyaddress

I'd also like to write something to disable/remove firewire and bluetooth from the network settings and disable ipv6 on each interface... these will be easy to do if I can figure out how to target the correct interfaces.

Thanks,
Ken

6 REPLIES 6

Kedgar
Contributor

I think I just answered my own question and wrote something that will work. I ended up using some code from setWebProxy.sh, but much of it is grabbed from elsewhere. Here it is for those that may want this... I'm sure it would be cleaner in perl, but I don't know it yet. Jamf comments are removed from the top to shorten this message.

#!/bin/bash
# VALUES ARE SET HERE
proxyAddress="http://webconfig.company.com/pac/webconfig.pac"
OS=`/usr/bin/defaults read /System/Library/CoreServices/SystemVersion ProductVersion | awk '{print substr($1,1,4)}'`

# Set Network Interfaces
if [[ "$OS" < "10.5" ]]; then ethInt1=$(/System/Library/CoreServices/RemoteManagement/ ARDAgent.app/Contents/Support/networksetup -listnetworkserviceorder | egrep [Ee]thernet | awk -F') ' '/()/ {print $2}' | awk 'NR==1'); ethInt2=$(/System/Library/CoreServices/RemoteManagement/ ARDAgent.app/Contents/Support/networksetup -listnetworkserviceorder | egrep [Ee]thernet | awk -F') ' '/()/ {print $2}' | awk 'NR==3'); airInt=$(/System/Library/CoreServices/RemoteManagement/ ARDAgent.app/Contents/Support/networksetup -listnetworkserviceorder | egrep [Aa]ir | awk -F') ' '/()/ {print $2}' | awk 'NR==1');
else ethInt1=$(/usr/sbin/networksetup -listnetworkserviceorder | egrep [Ee]thernet | awk -F') ' '/(
)/ {print $2}' | awk 'NR==1'); ethInt2=$(/usr/sbin/networksetup -listnetworkserviceorder | egrep [Ee]thernet | awk -F') ' '/()/ {print $2}' | awk 'NR==3'); airInt=$(/usr/sbin/networksetup -listnetworkserviceorder | egrep [Aa]ir | awk -F') ' '/()/ {print $2}' | awk 'NR==1');
fi

# Set Proxy for Ethernet Interfaces
if [[ "$OS" < "10.5" ]]; then echo "Setting Etehrnet Interface proxy for OS $OS..." /System/Library/CoreServices/RemoteManagement/ARDAgent.app/ Contents/Support/networksetup -setautoproxyurl "$ethInt1" "$proxyAddress" /System/Library/CoreServices/RemoteManagement/ARDAgent.app/ Contents/Support/networksetup -setautoproxyurl "$ethInt2" "$proxyAddress"
else echo "Setting Ethernet Interface proxy for OS $OS..." /usr/sbin/networksetup -setautoproxyurl "$ethInt1" "$proxyAddress" /usr/sbin/networksetup -setautoproxyurl "$ethInt2" "$proxyAddress"
fi

#Set Proxy for Airport Interface
if [[ "$OS" < "10.5" ]]; then echo "Setting Airport Interface proxy for OS $OS..." /System/Library/CoreServices/RemoteManagement/ARDAgent.app/ Contents/Support/networksetup -setautoproxyurl "$airInt" "$proxyAddress"
else echo "Setting Airport Interface proxy for OS $OS..." /usr/sbin/networksetup -setautoproxyurl "$airInt" "$proxyAddress"
fi

jarednichols
Honored Contributor

You can find the OS version a lot easier. Use sw_vers and case out for the
specific OS.

j

Kedgar
Contributor

Argh, the networksetup command in 10.4 and below does not support the - setproxyautoconfig flag. I'm testing to see if I can copy the networksetup binary to a 10.4 machine to make it work; my guess is that it won't.

tlarkin
Honored Contributor

I guess create and maintain separate scripts and set them up as custom trigger policies. Then set one master script that checks the OS via sw_vers command and does an if/then with a construct comparison and then triggers the custom trigger policy based on what the output is.



Thomas Larkin
TIS Department
KCKPS USD500
tlarki at kckps.org
blackberry: 913-449-7589
office: 913-627-0351
chown -R us /.base

Kedgar
Contributor

Thanks Thomas... that is a good easy way to do it. My new problem though is that I cannot seem to find a way to deploy a proxy pac file url to 10.4 machines. We still have about 68 of them that this solution doesn't work for.

tlarkin
Honored Contributor

Can you configure the file manually, and then snapshot that file change in Composer and use it to push that file out?