Skip to content

Instantly share code, notes, and snippets.

@ZackBoe
Created April 9, 2019 00:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZackBoe/1cd4e294688ebd011f399165a5c4e57a to your computer and use it in GitHub Desktop.
Save ZackBoe/1cd4e294688ebd011f399165a5c4e57a to your computer and use it in GitHub Desktop.
Domain lookup, including whois & certificate info. Supports pasting URLs, not just hostnames.
#!/bin/bash
# Get IP Geo & Org info from domain names.
# Requires jq, curl, dig, whois
lookup=${@: -1}
fqdn=`echo $lookup | cut -d'/' -f3 | cut -d':' -f1`
domain=$(expr match "$fqdn" '.*\.\(.*\..*\)')
doCert=0
doWhois=0
while getopts 'wch' flag; do
case "${flag}" in
w) doWhois=1 ;;
c) doCert=1 ;;
h) ;;&
*)
echo -e "dinfo [hostname or url]"
echo -e "-c: enable certificate check"
echo -e "-w: enable whois lookup"
exit 1 ;;
esac
done
if [ -z "$domain" ]
then
domain=$fqdn
fi
cyan='\e[36m'
clear="\e[39m"
if [ -z "$fqdn" ]
then
echo "Could not extract domain"
exit 1
else
ip=`dig +short $fqdn | tail -n1`
ipinfo=`curl -s https://ipinfo.io/$ip`
echo -e "FQDN: $cyan$fqdn$clear"
echo -e "IP: $cyan`echo "$ipinfo" | jq -r '.ip'`$clear"
echo -e "Hostname: $cyan`echo "$ipinfo" | jq -r '.hostname'`$clear"
echo -e "Location: $cyan[`echo "$ipinfo" | jq -r '.country'`] `echo "$ipinfo" | jq -r '.city'` `echo "$ipinfo" | jq -r '.region'`$clear"
echo -e "Org: $cyan`echo "$ipinfo" | jq -r '.org'`$clear"
echo -e "More: $cyan https://ipinfo.io/`echo -e $ipinfo | jq -r '.ip'`$clear"
if [[ $doCert == 1 ]]
then
certificate=`curl -fv https://$fqdn 2>&1 | awk 'BEGIN { cert=0 } /^\* SSL connection/ { cert=1 } /^\*/ { if (cert) print }'`
certvalid=`echo -e "$certificate" | grep "SSL certificate verify ok"`
if [ -n "$certvalid" ]
then
echo -e ""
echo -e "Cert CN: $cyan`echo -e \"$certificate\"| grep "subject: " | awk -F 'CN=' '{print $2}'`$clear"
echo -e "Cert CA: $cyan`echo -e \"$certificate\"| grep "issuer: " | awk -F '; ' '{print $2}' | awk -F 'O=' '{print $2}'`$clear"
echo -e "Cert Valid:$cyan`echo -e \"$certificate\"| grep "start date" | awk -F 'date:' '{print $2}'` -`echo -e \"$certificate\"| grep "expire date" | awk -F 'date:' '{print $2}'`$clear"
echo -e "More: $cyan https://www.ssllabs.com/ssltest/analyze.html?d=$fqdn&hideResults=on$clear"
fi
fi
if [[ $doWhois == 1 ]]
then
whois=`whois $domain`
echo -e ""
echo -e "Domain: $cyan$domain$clear"
echo -e "Registrar: $cyan`echo -e \"$whois\"| grep Registrar: | tail -n1 | awk -F ':' '{print $2}'` (`echo -e \"$whois\"| grep \"Registrar URL:\" | tail -n1 | awk -F 'URL: ' '{print $2}'`)$clear"
echo -e "Reg Dates: $cyan C:`echo -e \"$whois\"| grep \"Creation Date:\" | head -n1 | awk -F 'Date: ' '{print $2}' | awk -F 'T' '{print $1}'` U:`echo -e \"$whois\"| grep \"Updated Date:\" | head -n1 | awk -F 'Date: ' '{print $2}' | awk -F 'T' '{print $1}'` E:`echo -e \"$whois\"| grep \"Expiration Date:\" | head -n1 | awk -F 'Date: ' '{print $2}' | awk -F 'T' '{print $1}'`$clear"
echo -e "Nameserver:$cyan`echo -e \"$whois\"| grep \"Name Server:\" | head -n1 | awk -F ':' '{print $2}'`$clear"
echo -e "More: $cyan https://whois.icann.org/en/lookup?name=$domain$clear"
fi
fi
@ZackBoe
Copy link
Author

ZackBoe commented Apr 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment