Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Nslookup from an IP list - Batch?  (Read 22133 times)

0 Members and 1 Guest are viewing this topic.

deeboe

  • Guest
Nslookup from an IP list - Batch?
« on: February 01, 2006, 12:58:20 PM »
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??
« Last Edit: February 01, 2006, 01:00:04 PM by deeboe »

blazz0r

  • Guest
Re: Nslookup from an IP list - Batch?
« Reply #1 on: February 01, 2006, 03:53:49 PM »
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.

uli_glueck

  • Guest
Re: Nslookup from an IP list - Batch?
« Reply #2 on: February 02, 2006, 12:57:35 AM »
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
« Last Edit: February 02, 2006, 01:03:12 AM by uli_glueck »