Solved

Script required to find duplicate hostname resolve with DNS

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix, date minus 1, 2 or 3 days (last working day) 11 53
Shell script errors 10 132
Virtualizing TAPE on dual VIOS 3 87
Control Number of Log Files -Perl 7 72
Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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.
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.

776 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