Tuesday, 17 December 2013

Script to Convert List of Domains to IPs

I recently needed to do a bulk IP lookup of a set of domains. I hacked together the following bash script - it works but could be improved so feel free to send feedback.

Also, need to remeber if this is done by exporting an .xls to dos text then need to remove all the ^M (CNTRL V,M) from text files exported from DOS/Win first:
sed -e "s/^M//" filename > newfilename

#!/bin/bash 
# domainstoip.sh v1 - bulk domain to ip resolver script 
# Inputs: nix text file of domains (1 per line) 
# Outputs: domain_ip.txt 
# Known issues: resolves only one of the addresses if multiple returned from nslookup # 
# Usage: ./domainstoip.sh domains.txt 
# Copyright (C) 2013 Lazysecurity - http://lazysecurity.blogspot.co.uk/ 
# This program is free software: you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation, either version 3 of the License, or at 
# your option) any later version. 
# This program is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU General Public License for more details. 
# You should have received a copy of the GNU General Public License 
# along with this program. If not, see..
domainfile=$1  #get domains file 
echo -e "\n[+] IP lookups on the domains in "$domainfile":\n" > domain_ip.txt 
for domain in $(cat $domainfile);do #take each line in domains file and loop 
# grep Add gets all lines with Add 
# grep -v removes #53 line in nslookup 
# cut -f 2 -d ' ' = select field 2 and delimiter is space 
set `nslookup $domain | grep Add | grep -v '#' | cut -f 2 -d ' '` echo $domain': '$1';' >> domain_ip.txt done cat domain_ip.txt 
echo -e "\n[+] Done"

No comments:

Post a comment