Question

Locked

A Script to do the nslookup ??

By padma_chandran07 ·
It is one of my routine job to confrim the DNS entries resolving.

I normally do that by giving the command

nslookup DNSname/IP Address DNS-Server-IP
---------------------------- -------------------

I find this task is time consuming..when there are about 100 entries to check. Can anybody advice a better solution ?. I would be very much grateful.

This conversation is currently closed to new comments.

6 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

re: A Script to do the nslookup ??

by michael In reply to A Script to do the nslook ...

What scripting tool(s) do you have available? I might put all the entries in a file, then use a Perl script that uses that file as an input for a short FOREACH loop routine, outputting to screen or output file. Let me know if you need help with the Perl code, or have another script language in mind.

Michael

Collapse -

Thanks very much for your response Michael

by padma_chandran07 In reply to re: A Script to do the ns ...

I have got perl available. Will you be able to write a perl code for this?.

I have downloaded perl and just started to learn it by myself.

Collapse -

NSLOOKUP script in Perl

by michael In reply to Thanks very much for your ...

Here's a basic Perl script to print the results to the screen (no error checking):
[pre]
#!/usr/bin/perl

open (HOSTLIST,"lists.hosts");
@hosts = <HOSTLIST>;

foreach $host(@hosts) {
$results = `nslookup $host`;
chomp ($host);
print ("Results for $host:\n");
print ("=" x 50,"\n");
print ("$results\n\n");
}
close (HOSTLIST);
[/pre]
Modify the nslookup command between the backticks to meet your needs. The above assumes you've created a file called "lists.hosts" ahead of time. You could also use @ARGV to capture the input file name from the command line if you'd rather.

If you want to capture the results to a file instead of the screen, then at the top of the script open an output file:

open (RESULTFILE,">results.txt"); #open for overwrite
or
open (RESULTFILE,">>results.txt"); #open for append

Then change all your output print commands to:

print (RESULTFILE "$results & text/variables here");

Finally, include the output file in your close command:

close (HOSTFILE,RESULTFILE);

Get the O'Reilly book "Learning Perl" if you haven't already. It's a great starting point. Let me know if you need anything else.

Michael

Collapse -

use a batch file?

by ashij In reply to A Script to do the nslook ...

Hey Padma, fomr whatI understand, You have a list of IPs (100) and you'd like to run an nslookup on all of them without having to repeat the steps everytime. So I thought maybe you could do it with a batch script. I know you wanna learn Perl, but maybe you can do that later as well. Here's the Batch script (I will not take credit for this code, originally not from me):

[pre]

@echo off
if exist list.txt del list.txt

:: list of name servers
for %%i in (69.54.120.1xx
69.54.120.2xx ) do (

:: list of sites
for %%j in (192.168.xxx.1xx
192.168.xxx.2xx
192.168.xxx.3xx
192.168.xxx.4xx ) do (

for /f "tokens=1*" %%k in ('nslookup %%j %%i') do (
if [%%k]==[Server:] set server=%%l
if [%%k]==[Address:] set address=%%l
if [%%k]==[Addresses:] set address=%%l
if [%%k]==[Name:] set name=%%l)
call echo %date% , %%server%% , %%name%% , %%address%%>>list.txt
)
)

[/pre]
Explanation:
list.txt is the name of file that the result will get saved to. This file usually gets saved under the user-account name (c:\documents and settings\%username%\)

the address : 69.54.120.1xx and 2xx are the two DNS servers

The addresses: 192.168.20.1xx, 2xx .. are the IP's that you want to get resolved.

To use, save everything startingfrom "@ECHO" till the two "))" into a filename.bat and just execute.

Hope this helps.

Ash

edit:making it pretty

Collapse -

Small correction on batch script

by shah_appu In reply to use a batch file?

@echo off
if exist list.txt del list.txt


for %%i in (69.54.120.1xx
69.54.120.2xx ) do (


for %%j in (192.168.xxx.1xx
192.168.xxx.2xx
192.168.xxx.3xx
192.168.xxx.4xx ) do (

for /f "tokens=1*" %%k in ('nslookup %%j %%i') do (
if [%%k]==[Server:] set server=%%l
if [%%k]==[Address:] set address=%%l
if [%%k]==[Addresses:] set address=%%l
if [%%k]==[Name:] set name=%%l)
call echo %date% , %time% , %%j , %%name%% >>list.txt
)
)

Collapse -

multiple dns

by mhd.ganji In reply to A Script to do the nslook ...

hi
it is good
but it doesnt give all ip addresses
for example google has returned 5 addresses in my nslookup run
but the script writes just one
how should be the correction ?

Back to Networks Forum
6 total posts (Page 1 of 1)  

Related Discussions

Related Forums