Solved

Script required to find duplicate hostname resolve with DNS

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.

691 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