Created
January 24, 2019 09:29
-
-
Save vijay922/dc1a0857c9f054e9edbd9c8ff2af5051 to your computer and use it in GitHub Desktop.
Domain 2 IP in Bash
This file contains 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 | |
# Usage: ./domain2ip.sh [domain-list-file] [output-file] | |
echo -e "[+] domain2ip.sh by @vijay922\n" | |
if [ -z "$1" ] || [ -z "$2" ]; then | |
echo "[!] Usage: ./domain2ip.sh [domain-list-file] [output-file]" | |
exit 1 | |
fi | |
echo "[+] Resolving domains to IPs..." | |
while read d || [[ -n $d ]]; do | |
ip=$(dig +short $d|grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"|head -1) | |
if [ -n "$ip" ]; then | |
echo "[+] '$d' => $ip" | |
echo $ip >> $2 | |
else | |
echo "[!] '$d' => [RESOLVE ERROR]" | |
fi | |
done < $1 | |
echo -e "\n[+] Removing duplicates..." | |
sort $2 | uniq > $2.new | |
mv $2.new $2 | |
echo -e "\n[+] Done, IPs saved to '$2'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment