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.

Revisions

  1. micalm created this gist Jul 17, 2024.
    25 changes: 25 additions & 0 deletions hhost.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/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