I have faced many sitiation in my IT career where I have to get host names from alist of IP address & sometime ipaddress to hostnames. I have researched on internet & found two useful scripts but never got a time to share it on my blog. Today I got the same situation & I used those scripts to accomplish my task.
Below are the two scripts:-
1. Hostname to Ip address( it will take input from text file & resturn in CSV)
@echo off
set ComputerList=C:\hostname\hostname.txt
Echo Computername,IP Address>Final.csv
setlocal enabledelayedexpansion
for /f “usebackq tokens=*” %%A in (“%ComputerList%”) do (
for /f “tokens=3” %%B in (‘ping -n 1 -l 1 %%A ^|findstr Reply’) do (
set IPadd=%%B
echo %%A,!IPadd:~0,-1!>>final.csv
))
2. IP address to hostnames( it will take input from text file & resturn in txt file)
@echo off
for /F %%a in (‘type c:\hostname\ip.txt’) do call :Sub %%a
goto :eof
:Sub
for /F %%b in (‘nbtstat -A %1 ^| find “<00>” ^| find /i “unique”‘) do echo %1 Hostname %%b
Thanks to the scripters that created these scripts.
This tiny tool also can help;
http://sourceforge.net/projects/iphostnameconverter/