RESOLVER – Script to resolve a list of hostnames to their IP addresses

This script will translate a list of IP addresses from a .txt file, in columns to a .csv file in the same directory as the script resides, of course you can edit the code as you like.

Here is the code:

@echo
setlocal enabledelayedexpansion

set input=computerlist.txt
set output=computerlist.csv

for /F %%G in ('type "%input%"') do (
 set ip=

 for /F "tokens=* skip=2" %%H in ('nslookup %%G 2^>NUL') do (
  set line=%%H
  if "!line:~0,8!"=="Address:" set ip=!line:~10!
  if "!line:~0,10!"=="Addresses:" set ip=!line:~12!
 )

 echo %%G,!ip!>>"%output%"
)

To make it work you need to create a .cmd file with this code and save it into a folder.

In the same directory you need to create a file named computerlist.txt where there are all the hostnames to be translated.

The rest is just double click the .cmd file and in the same folder will be created a file computerlist.csv.

If you don’t want to see the “many things” on the “black window”, you can turn off the echo, just changing the code from @echo to @echo off

Regards

Any question? You need our FAST help? Go to our forum and as for FREE!

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>