Created
July 17, 2024 13:45
-
-
Save micalm/4c3c3a06a687772485abcefc6275c8f2 to your computer and use it in GitHub Desktop.
`host` that does revdns automatically
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 | |
| 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