DNS Servers extension attribute for Yosemite

burdett
Contributor II

Has any one updated the DNS Servers extension attribute script to work for Yosemite? The results I get from this EA is, "The networksetup binary is not present on this machine."

5 REPLIES 5

davidacland
Honored Contributor II
Honored Contributor II

It looks like its mis-calculating the OS version. /usr/bin/sw_vers -productVersion | /usr/bin/colrm 5 on 10.10.x gives you 10.1 and there is an if statement that says if OS is less than 10.5 use /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup. There is then another check to see if /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup exists and if it doesn't, display "The networksetup binary is not present on this machine".

The rest of the code works ok so assuming you don't have any 10.4 or earlier clients anymore, I would just take out the OS version check section.

davidacland
Honored Contributor II
Honored Contributor II

The simpler version would look like:

#!/bin/sh
NetworkInterface=`/usr/sbin/networksetup -listnetworkserviceorder 2>&1 | grep $(/usr/sbin/netstat -rn 2>&1 | /usr/bin/grep -m 1 'default' | /usr/bin/awk '{ print $6 }') | sed -e "s/.*Port: //g" -e "s/,.*//g"`
echo "<result>`/usr/sbin/networksetup -getdnsservers "$NetworkInterface" 2>&1`</result>"

burdett
Contributor II

simpler is usually better, The simpler version is working great.
Thanks David

sean
Valued Contributor

This also wont show DNS that are provided by a DHCP server, just locally configured DNS.

The command is looking for DNS set on a particular interface, however DNS from your DHCP server will provide this for any interface.

This may of course be what you are looking for, to check if anyone has set any alternative DNS.

/usr/sbin/networksetup -getdnsservers Ethernet
There aren't any DNS Servers set on Ethernet.

mm2270
Legendary Contributor III

There is a way to pull the DHCP provided DNS entries, but it may not be the cleanest or most reliable method.

Seems scutil --dns will list all DNS related entries. Also, resolver #1, which gets listed a second time under the scoped entries section, is usually your default or active network service (though I've read this is not 100% accurate)
Given the above, if you can rely on resolver #1 being your active service, the following should list any DHCP provided DNS entries. Interestingly in my tests, this also shows any locally set DNS entries, which override DHCP provided ones. So it will list either type actually.

/usr/sbin/scutil --dns | awk '/scoped queries/,/END/{print}' | awk '/nameserver/{print $NF}'

You can also use the same method to list the search domains by adjusting it slightly.

/usr/sbin/scutil --dns | awk '/scoped queries/,/END/{print}' | awk '/search domain/{print $NF}'