I'm trying to write a bash script for OS X that will change will add a nameserver for the current connection. I've got the command to change the DNS servers but I need to preserve the current namesever.
What I thought is that I could get the current nameserver out of the resolv.conf file and then use this somehow in the command.
I've currently got this to change the nameserver to 188.8.131.52:
networksetup -setdnsservers AirPort 184.108.40.206
What I need to do is detect the current nameserver from /etc/resolv.conf and then use the value as a param in the above command. For example say my current resolv.conf looks like this:
I want the above to command to do this:
networksetup -setdnsservers AirPort 220.127.116.11, 18.104.22.168
Is there a way to use regular expression to extract the IP from resolv.conf and then somehow use this as an argument in the networksetup command?