
Description:
A super simple CLI for pulling domain whois requests directly from whois.com to the terminal
Usage:
whois <url>
Commands:
-v Show version
Examples:
whois
whois facebook.com
#!/bin/bash
#
#
#######################
# GLOBAL VARIABLES
########################
VERSION="1.3"
####################
# COLOUR VARIABLES
####################
# Terminal Formatting
RESET="\033[0m"
BOLD="\033[1m"
# UI Colours
CLR_RED="\033[38;5;196m" # Bright Red
CLR_GREEN="\033[38;5;46m" # Bright Lime Green
CLR_GOLD="\033[38;5;226m" # Gold
CLR_PURPLE="\033[38;5;141m" # Light Purple / Lavender
CLR_BLUE="\033[38;5;4m" # Bright Sky Blue
CLR_ORANGE="\033[38;5;208m" # Orange
CLR_AQUA="\033[38;5;51m" # Aqua
CLR_PINK="\033[38;5;199m" # PINK
CLR_PBLUEE="\033[38;5;147m" # Pale Blue
CLR_DGREEN="\033[38;5;2m" # Dark Forest Green
CLR_PAQUA="\033[38;5;195m" # Pale Aqua
CLR_GREY="\033[38;5;245m" # Darker Grey
CLR_TEXT="\033[38;5;250m" # Light Grey
####################
# VERSION
####################
if [[ "$1" == "-v" ]]; then
echo -e " ${CLR_PURPLE}Simple Domain Lookup v${VERSION}${RESET}"
exit 0
fi
####################
# GET URL
####################
if [[ -n "$1" ]]; then
URL="$1"
else
echo -e "${CLR_AQUA}Enter WHOIS Lookup URL:${RESET}"
read URL
fi
####################
# DOWNLOAD WHOIS
####################
wget -q -nv -O output.html "https://who.is/whois/$URL"
####################
# CHECK FOR RESULTS
####################
if ! grep -q "Contact Information" output.html; then
echo
echo -e "${CLR_RED}Error: ${RESET}No Records Found"
echo
rm output.html
exit 1
fi
echo "─────────────────────────────────────"
echo -e "${BOLD}${CLR_GOLD} WHOIS reply for:${RESET}${CLR_GOLD} $URL${RESET}"
echo "─────────────────────────────────────"
####################
# EXTRACT WHOIS DATA
####################
get_field() {
grep -oP "$1: \K[^\\\\\"]+" output.html | head -1
}
echo -e "${CLR_AQUA}Registrant Contact${RESET}"
echo -e " ${CLR_TEXT}Name${RESET} : ${BOLD}$(get_field "Registrant Name")${RESET}"
echo -e " ${CLR_TEXT}Address${RESET} : ${BOLD}$(get_field "Registrant Street"), $(get_field "Registrant City"), $(get_field "Registrant State/Province") $(get_field "Registrant Postal Code"), $(get_field "Registrant Country")${RESET}"
echo -e " ${CLR_TEXT}Phone${RESET} : ${BOLD}$(get_field "Registrant Phone")${RESET}"
echo -e " ${CLR_TEXT}Email${RESET} : ${BOLD}$(get_field "Registrant Email")${RESET}"
echo
echo -e "${CLR_AQUA}Registrar Information${RESET}"
echo -e " ${CLR_TEXT}Registrar${RESET} : ${BOLD}$(get_field "Registrar")${RESET}"
echo -e " ${CLR_TEXT}WHOIS Server${RESET}: ${BOLD}$(get_field "Registrar WHOIS Server")${RESET}"
echo -e " ${CLR_TEXT}Abuse Email${RESET} : ${BOLD}$(get_field "Registrar Abuse Contact Email")${RESET}"
echo -e " ${CLR_TEXT}Abuse Phone${RESET} : ${BOLD}$(get_field "Registrar Abuse Contact Phone")${RESET}"
echo
echo -e "${CLR_AQUA}Important Dates${RESET}"
echo -e " ${CLR_TEXT}Created${RESET} : ${BOLD}$(get_field "Creation Date")${RESET}"
echo -e " ${CLR_TEXT}Updated${RESET} : ${BOLD}$(get_field "Updated Date")${RESET}"
echo -e " ${CLR_TEXT}Expires${RESET} : ${BOLD}$(get_field "Registrar Registration Expiration Date")${RESET}"
echo
echo -e "${CLR_AQUA}Nameservers${RESET}"
grep -oP 'Name Server: \K[^\\\\"]+' output.html |
sort -u |
while read -r nameserver; do
echo -e " ${CLR_TEXT} ${RESET}${BOLD}$nameserver${RESET}"
done
echo
echo "────────────────────────────────"
####################
# CLEANUP
####################
rm output.html
