1.

Solve : Nslookup from an IP list - Batch??

Answer»

Hello,

I have used this formum for a long time now, but am finally registered to ask a question. Soon I hope to help provide feedback to people too.

My question is this though, can anyone think of a way to create a batch file to do the following:

1. Input a list of known computer names
2. USE nslookup to find each computer's IP address
3. Output each address into a seperate file

I know that may seem like a lot to ask for the first question, but I am drawing a blank here. My main problem is the output I currently get this:

C:\>nslookup SERVERNAME.com
Server: mydns.com
Address: xxx.xxx.xxx.xxx

Name: SERVERNAME.com
Address: xxx.xxx.xxx.xxx [highlight]<-----THIS IS ALL I WANT[/highlight]
Aliases: SERVERNAME2.com

Any thoughts??To find just the ip address, you can pipe the output of Nslookup to the find command.


nslookup www.google.com | find "Address"

this SPITS you out more than just the address, so you need to configure it a bit more.
From the initial nslookup, figure out what the IP of your computer's nameserver is. (you said mydns.com in your example)
So now we can eliminate that field's address

nslookup www.google.com | find "Address" | find /v "xxx.xxx.xxx.xxx"

That should POP your answer out in one of two ways.

1. Address: xxx.xxx.xxx.xxx
2. Non-authoritative answer:
Address: xxx.xxx.xxx.xxx

I haven't figured out how to get rid of the Non-autoritative answer: yet, but I hope this gets you going in the right direction.

As far as how to get these into separate files, I would write a simple vbscript that reads from a file and loops through EXECUTING this batch file untill all addresses are used.This should do the job:

@echo off
set pclist=your list with the machines
for /f %%a in (type %pclist%) do call :SUB %%a

set pc=
goto :EOF
SUB: %%a

set pc=%1
for /f "skip=1 tokens=1,2 delims=:" %%a in ('nslookup %pc% ^|find /i "Address"') do echo %%a%%b >%pc%.txt

:EOF

hope this helps
uli



Discussion

No Comment Found