Last active
August 29, 2015 14:26
-
-
Save jottr/1fd28960ef10c02cffc1 to your computer and use it in GitHub Desktop.
This script quickly switches between different dns servers...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage="$(basename "$0") sets the DNS for the wifi network to one of the following: | |
[-n]ative: sets to local DNS | |
[-g]oogle: sets to google DNS | |
[-t]unlr: sets to tunlr DNS | |
[-h]elp prints this help message. | |
" | |
native="empty" | |
google="8.8.8.8 8.8.4.4" | |
tunlr="45.33.81.76 45.33.12.13" | |
while getopts ":hngt" opt; do | |
case $opt in | |
h) | |
echo "$usage" | |
;; | |
n) | |
dns=$native | |
;; | |
g) | |
dns=$google | |
;; | |
t) | |
dns=$tunlr | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
esac | |
done | |
if $( networksetup -setdnsservers Wi-Fi $dns ); then | |
echo "Set DNS to" $dns | |
else | |
echo "Failed to set DNS" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment