Skip to content

Instantly share code, notes, and snippets.

@micalm
Created July 17, 2024 13:45
Show Gist options
  • Save micalm/4c3c3a06a687772485abcefc6275c8f2 to your computer and use it in GitHub Desktop.
Save micalm/4c3c3a06a687772485abcefc6275c8f2 to your computer and use it in GitHub Desktop.
`host` that does revdns automatically
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: host <domain>"
exit 1
fi
DOMAIN="$1"
# Perform the DNS lookup for the domain
IP=$(host $DOMAIN | awk '/has address/ { print $4 }')
if [ -z "$IP" ]; then
echo "No IP address found for $DOMAIN"
exit 1
fi
# Perform the reverse DNS lookup for the IP
HOSTNAME=$(host $IP | awk '/domain name pointer/ { print $5 }' | sed 's/\.$//')
if [ -z "$HOSTNAME" ]; then
echo "$DOMAIN => $IP"
else
echo "$DOMAIN => $IP => $HOSTNAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment