Last active
December 20, 2015 19:00
-
-
Save mstade/aa273c6227ebb660fd45 to your computer and use it in GitHub Desktop.
unblock-us toggle
This file contains hidden or 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
# Unblock-US toggler | |
function unblock-us() { | |
local status="${1}" | |
local default="Wi-Fi" | |
local service="${2:-${default}}" | |
if [[ "${status}" == "on" ]]; then | |
local dns=(208.122.23.23 208.122.23.22) | |
elif [[ "${status}" == "off" ]]; then | |
local dns="empty" | |
else | |
local IFS=$'\n' | |
local svclist=($(networksetup -listallnetworkservices)) | |
cat<<-USAGE | |
usage: unblock-us on|off [<service>] | |
commands: | |
on Enables the Unblock-US DNS. | |
off Disables the Unblock-US DNS. | |
arguments: | |
<service> The service used for the Unblock-US DNS; | |
defaults to '${default}' if not specified. | |
services: | |
$(printf ' %s\n' "${svclist[@]}") | |
USAGE | |
printf "${status:+\n"error: invalid option '${status}'"\n}" | |
return 1 | |
fi | |
sudo networksetup -setdnsservers ${service} ${dns[@]} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment