Solved

Script required to find duplicate hostname resolve with DNS

Posted on 2009-07-05
2
838 Views
Last Modified: 2013-11-17
Script required to find duplicate hostname resolve with DNS
        In our build environment we want find Duplicate hostname entry against all. We need a script which will run following logic

1.get IPs from file
2. run nslookup <ipaddress1> - it will give hostname1  (it will give only one hostname)
 then again  I need  to type same Ip again to get second hostname.(dublicate hostname)
 nslookup <ipaddress1> it will give hostname2 ( In this example hostname1 and hostname2 pointing to same IP)

So what i need is  nslookup <ipaddress> part need to run two times one after another continuously and outputs need to be compared. If output hostnames differs it need to be pasted as duplicate hostname entry for that IP. if it hostname didn't vary the output don't need to be reported.
        help please.
0
Comment
Question by:rammaghenthar
2 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 24780863
do you own / manage the dns server for the reverse lookup zone? if yes , then you can do simple

grep ipaddress zonefile

to find duplicates
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 24781584
OK,

and if not, here is the script.

Good luck!

wmp






#!/bin/ksh
 
iplist=/file/containing/ipaddresses
result=/file/containing/result
errors=/file/conatining/errors
 
rm $result 2>/dev/null
rm $errors 2>/dev/null
 
while read -r ip
  do
    host1=$(nslookup "$ip" 2>>$errors | tail +3 | grep "Name:" | awk '{print $2}')
    host2=$(nslookup "$ip" 2>>$errors | tail +3 | grep "Name:" | awk '{print $2}')
    [ ${host1}x = "x" -o ${host2}x = "x" ] && continue
    [ $host1 != $host2 ] && echo "$ip resolves to $host1 AND $host2" >> $result
  done < $iplist
exit

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question