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 22.214.171.124:
networksetup -setdnsservers AirPort 126.96.36.199
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 188.8.131.52, 184.108.40.206
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?