Solved

Script required to find duplicate hostname resolve with DNS

Posted on 2009-07-05
2
834 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

758 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now