?
Solved

Script required to find duplicate hostname resolve with DNS

Posted on 2009-07-05
2
Medium Priority
?
857 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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 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.
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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