I have a list of 2 /24s worth of IP addresses in seperate text files. What I am interested in doing is finding a way to resolve the hosts of these IP addresses and filter out to display only the top level domain.

for example; resolves to www.mywebsite.com

using shell scripting would it then be possible to filter out and append the result to a new file displaying resolves to mywebsite.com

the reason for this is internally in the given /24s I am working with I have virtual machines such as web1-10 and mail-10 and i'd like to filter these matches to know only the domains I am running on my netblocks.

Thank you very much Team, I appreciate any assistance to help find a solution with this.

Best, Nick

2 Answers 2

for IP in $(cat file1.txt file2.txt); do
  echo "$IP resolves to $(dig +short -x $IP)"

once you have resolved the names, pipe your output to this :

awk -F'.' -v OFS='.' '{print $(NF-1),$NF}'

credit : http://groups.google.com/group/comp.lang.awk/browse_thread/thread/518fadbf02c4eb74?pli=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.