Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Greetings,

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; 192.168.1.1 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 192.168.1.1 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

share|improve this question

2 Answers 2

up vote 1 down vote accepted
for IP in $(cat file1.txt file2.txt); do
  echo "$IP resolves to $(dig +short -x $IP)"
done
share|improve this answer

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%5Fthread/thread/518fadbf02c4eb74?pli=1

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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