Last active
August 29, 2015 14:26
-
-
Save sahal/d99a94597381b2f908df to your computer and use it in GitHub Desktop.
add this as an alias for whois to account for whois servers that your machine doesn't know about yet. see: http://blog.sahal.info/post/125728360746/whois-servers-for-gtlds
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
| #!/bin/bash | |
| # ./whois-test.sh domain.test.gtld | |
| # desc: add this as an alias for whois to account for whois servers that your machine doesn't know about yet | |
| # see: http://blog.sahal.info/post/125728360746/whois-servers-for-gtlds | |
| # by: sahal ansari github@sahal.info | |
| PATH_TO_WHOIS="/usr/bin/whois" | |
| # test parameters and set the first potential domain as the DOMAIN_IN_QUESTION | |
| #for parameter in "$@"; do | |
| # # very simple check for domain (also matches ip addresses) | |
| # if grep -E '.*\.' <<< "$parameter" &> /dev/null ; then | |
| # echo "$parameter"" might be the domain you're looking to lookup" | |
| # DOMAIN_IN_QUESTION="$parameter" | |
| # break | |
| # fi | |
| #done | |
| # if you give the script more than one parameter we're gonna pass | |
| # everything to the whois command b/c its too complicated | |
| if [ "$#" -ne "1" ]; then | |
| $PATH_TO_WHOIS "$@" | |
| else | |
| DOMAIN_IN_QUESTION="$1" | |
| fi | |
| # If your machine doesn't have a /etc/whois.conf then this script will query whois.iana.org for EVERY whois lookup | |
| # therefore, it is recommended that you import Demain's whois.conf into /etc/whois.conf prior to running this script | |
| # see: https://thde.io/whois-command-line-new-gtld-guru-watch-zone-link/ | |
| if ! grep \\\\.$(sed s/.*\\.// <<< "$DOMAIN_IN_QUESTION")\\$ /etc/whois.conf &> /dev/null ; then | |
| TEST_WHOIS_SERVER="$(whois $(sed s/.*\\.// <<< "$DOMAIN_IN_QUESTION") -h whois.iana.org|grep whois\:|sed -e s/whois\:\\s*//)" | |
| if [ -z $TEST_WHOIS_SERVER ];then | |
| echo "no whois server found." | |
| exit 1 | |
| fi | |
| export WHOIS_SERVER=$TEST_WHOIS_SERVER | |
| # i'm not sure why whois isn't using this exported environmental variable, WHOIS SERVER, so i used -h instead | |
| $PATH_TO_WHOIS "$DOMAIN_IN_QUESTION" -h "$WHOIS_SERVER" | |
| exit 0 | |
| fi | |
| # if the gTLD is listed in /etc/whois.conf then we can safely assume this will return whois for the $DOMAIN_IN_QUESTION | |
| $PATH_TO_WHOIS "$DOMAIN_IN_QUESTION" |
Author
Author
TODO: Fix handling of non-ascii gTLDs or internationalized country code TLDs by encoding them in ascii (i.e. .中国 will not be encoded as .zhongguo or .xn--fiqs8s) As it stands, the script will not (always) be able to grep for these types of gTLDs in /etc/whois.conf.
Apparently, this type of encoding of unicode into ascii is called Punycode.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: An older version of this script (see revision history) only worked for superficial uses of whois. If you’re using whois with any commandline parameters the script would fail.
As of 2015-08-03 Central Time: It should now be "safe" to use this script as an alias for the whois command. Feel free to provide the above script as many parameters as you wish. If you give it more than one parameter, it'll pass all parameters to the whois command.
If you provide the script only one parameter (e.g. ./whois-test.sh $DOMAIN_IN_QUESTION) the script will try to find the whois server associated with that gTLD and then look in /etc/whois.conf to see if the whois server is already listed. If the server isn't listed, it'll query whois.iana.org to find the whois server. Finally, it'll lookup whois for the $DOMAIN_IN_QUESTION.