Created
July 4, 2011 03:14
-
-
Save kastiglione/1062860 to your computer and use it in GitHub Desktop.
Hostname banning zsh function
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
# assumes control of all hosts in /Local/Default/Hosts | |
# https://gist.github.com/1062860 | |
hostoggle() { | |
if (( ${#*} == 0 )); then | |
# no host given, print current list of hosts banned | |
dscl . -ls Hosts | |
fi | |
for host in "$@"; do | |
if $(dscl . -read Hosts/$host >&- 2>&-); then | |
# delete existing host records (raw and www-less) | |
sudo dscl . -delete Hosts/$host | |
[[ "$host" =~ "^www\." ]] && sudo dscl . -delete "Hosts/${host#www.}" >&- 2>&- | |
else | |
# create host record misdirection (raw and www-less) | |
sudo dscl . -create Hosts/$host IPAddress 127.0.0.1 | |
[[ "$host" =~ "^www\." ]] && sudo dscl . -create "Hosts/${host#www.}" IPaddress 127.0.0.1 | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment