Skip to content

Instantly share code, notes, and snippets.

@dale-c-anderson
Created January 19, 2016 22:46
Show Gist options
  • Save dale-c-anderson/dd870213ed18908620bd to your computer and use it in GitHub Desktop.
Save dale-c-anderson/dd870213ed18908620bd to your computer and use it in GitHub Desktop.
Does some lookups to help find out where a machine or domain is hosted, given a dns name or IP address.
#!/bin/bash
# Show some help
if (( $# != 1 )); then
echo ""
echo "Usage: $(basename $0) <domain.com>"
echo "Does some lookups to help find out where a website is hosted, given a domain name."
echo ""
exit 1
fi
STOPPERS=''
type dig >/dev/null 2>&1 || { STOPPERS="$STOPPERS
dig"; }
type host >/dev/null 2>&1 || { STOPPERS="$STOPPERS
host"; }
type whois >/dev/null 2>&1 || { STOPPERS="$STOPPERS
whois"; }
type getent >/dev/null 2>&1 || { STOPPERS="$STOPPERS
getent (comes with glibc)"; }
if [[ "$STOPPERS" != '' ]]; then
echo >&2 "The following programs are required for this script to run: $STOPPERS"
exit 1;
fi
# Get the IP address for the domain
domain_name="$1"
ip_address=$(getent hosts "$domain_name" | awk '{ print $1 }')
STATUS=$?
if [ $STATUS -ne 0 ]; then
exit $STATUS
fi
echo "ip: $ip_address"
if [[ "$ip_address" == '' ]]; then
echo "Could not find IP address for domain name."
exit 1
fi
# Get the hostname (PTR) record for the IP addrses
ptr_host=$(host "$ip_address")
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo "host command failed. No PTR record exist for $ip_address"
fi
echo "host: $ptr_host"
echo -n "Press any key to do an IP whois, or ctrl+c to abort: "
read dramatic_pause
# Do an IP whois lookup
ip_whois_result=$(whois "$ip_address")
STATUS=$?
if [ $STATUS -ne 0 ]; then
exit $STATUS
fi
echo "$ip_whois_result"
echo -n "Press enter to do an regular whois, or ctrl+c to abort: "
read dramatic_pause
# Do a regular whois lookup
name_whois_result=$(whois "$domain_name")
STATUS=$?
if [ $STATUS -ne 0 ]; then
exit $STATUS
fi
echo "$name_whois_result"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment