Skip to content

Instantly share code, notes, and snippets.

@goncalor
Created December 19, 2021 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goncalor/b4a377b98abc27d7fcf0efaeaf679819 to your computer and use it in GitHub Desktop.
Save goncalor/b4a377b98abc27d7fcf0efaeaf679819 to your computer and use it in GitHub Desktop.
Scripts to resolve domains to IPs
/NXDOMAIN/ {print $2, "?"; next}
/SERVFAIL/ {print $2, "?"; next}
/mail is handled by/ {next}
/is an alias for/ {doms[$6]=$1; next}
{
if ($1"." in doms)
print doms[$1"."], $4
else if (match($0, "has IPv6 address"))
print $1, $5
else
print $1, $4
}
# This script processes a domain list such as this one
# example.com has address 93.184.216.34
# example.com has IPv6 address 2606:2800:220:1:248:1893:25c8:1946
# example.com mail is handled by 0 .
# Host nx.example.com not found: 3(NXDOMAIN)
#
# and outputs the following format
# $ awk -f convert.awk domains-resolved.txt
# example.com 93.184.216.34
# example.com 2606:2800:220:1:248:1893:25c8:1946
# nx.example.com ?
#/urs/bin/env bash
xargs -n 1 host 2>&1
# cat domains.txt | ./resolve.sh | tee domains-resolved.txt
# Be careful about line terminators on the input. Ensure \n only is used, UNIX style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment