Skip to content

Instantly share code, notes, and snippets.

@jamie-dit
Forked from chrisdavidmiles/bulk_dig.sh
Created July 4, 2022 01:38
Show Gist options
  • Save jamie-dit/6a39117b2e420066a936681684a34e1c to your computer and use it in GitHub Desktop.
Save jamie-dit/6a39117b2e420066a936681684a34e1c to your computer and use it in GitHub Desktop.

Revisions

  1. @chrisdavidmiles chrisdavidmiles revised this gist May 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bulk_dig.sh
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,4 @@ do
    whois $ip | grep -i 'netname' | awk '{print $NF}' | xargs
    fi
    sleep $loop_wait # Pause before the next lookup to avoid flooding NS
    done;
    done
  2. @chrisdavidmiles chrisdavidmiles revised this gist May 6, 2022. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions bulk_dig.sh
    Original file line number Diff line number Diff line change
    @@ -11,16 +11,16 @@ ns_ip='1.1.1.1' # Is using Cloudflare's 1.1.1.1.
    # Seconds to wait between lookups:
    loop_wait='1' # Is set to 1 second.

    echo "Domain name, IP Address, IP PTR, IP NetName (WHOIS)"; # Start CSV
    for domain in `cat $domain_list` # Start looping through domains
    echo 'Domain name, IP Address, IP PTR, IP NetName (WHOIS)' # Start CSV
    for domain in $(cat $domain_list) # Start looping through domains
    do
    ip=`dig @$ns_ip +short $domain |tail -n1`; # IP address lookup
    if [ ! -n "$ip" ] # If the IP is null (expired or invalid domain)
    ip=$(dig @$ns_ip +short $domain | tail -n1) # IP address lookup
    if [ -z "$ip" ] # If the IP is null (expired or invalid domain)
    then # Then
    echo "$domain,No DNS,,"; # Write "No DNS" in the IP column
    echo "$domain,No DNS,," # Write "No DNS" in the IP column
    else # And if an IP is found perform a PTR and NetName lookup
    echo -en "$domain,$ip,"`dig @$ns_ip +short -x $ip |xargs`",";
    whois $ip |grep -i 'netname' |awk '{print $NF}'|xargs;
    echo -en "$domain,$ip,"$(dig @$ns_ip +short -x $ip | xargs)','
    whois $ip | grep -i 'netname' | awk '{print $NF}' | xargs
    fi
    sleep $loop_wait # Pause before the next lookup to avoid flooding NS
    done;
    done;
  3. @chrisdavidmiles chrisdavidmiles revised this gist Feb 19, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion bulk_dig.sh
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,7 @@ do
    echo "$domain,No DNS,,"; # Write "No DNS" in the IP column
    else # And if an IP is found perform a PTR and NetName lookup
    echo -en "$domain,$ip,"`dig @$ns_ip +short -x $ip |xargs`",";
    whois $ip |grep NetName |awk '{print $NF}'|xargs;
    whois $ip |grep -i 'netname' |awk '{print $NF}'|xargs;
    fi
    sleep $loop_wait # Pause before the next lookup to avoid flooding NS
    done;
  4. @chrisdavidmiles chrisdavidmiles created this gist Feb 18, 2019.
    26 changes: 26 additions & 0 deletions bulk_dig.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/bin/bash
    # Bulk DNS Lookup
    # Generates a CSV of DNS lookups from a list of domains.
    #
    # File name/path of domain list:
    domain_list='domains.txt' # One FQDN per line in file.
    #
    # IP address of the nameserver used for lookups:
    ns_ip='1.1.1.1' # Is using Cloudflare's 1.1.1.1.
    #
    # Seconds to wait between lookups:
    loop_wait='1' # Is set to 1 second.

    echo "Domain name, IP Address, IP PTR, IP NetName (WHOIS)"; # Start CSV
    for domain in `cat $domain_list` # Start looping through domains
    do
    ip=`dig @$ns_ip +short $domain |tail -n1`; # IP address lookup
    if [ ! -n "$ip" ] # If the IP is null (expired or invalid domain)
    then # Then
    echo "$domain,No DNS,,"; # Write "No DNS" in the IP column
    else # And if an IP is found perform a PTR and NetName lookup
    echo -en "$domain,$ip,"`dig @$ns_ip +short -x $ip |xargs`",";
    whois $ip |grep NetName |awk '{print $NF}'|xargs;
    fi
    sleep $loop_wait # Pause before the next lookup to avoid flooding NS
    done;