Resolve IP to Host Names

December 16, 2010 at 06:25:39
Specs: Windows XP
I have one code which when executed takes the input file in which host names are mentioned and gives the output ie the IP address but i want the other way around.... i mean i ll save IP address in input file and i want host names.... i will paste the code which i have..

@echo off
set ComputerList=C:\hi.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

So please reply with the code ASAP..


See More: Resolve IP to Host Names

Report •

December 16, 2010 at 07:21:58
Use the command "dig" to resolve ip addresses to names (providing the DNS server has the correct reverse zones - otherwise you can't do it). You'll have to write the code yourself.

Report •

December 16, 2010 at 07:35:27
dig is a linux command.

Windows has nslookup. The restriction of having reverse lookup enabled on the DNS server exists regardless of the actual program, though.


@SET /P ip=What IP?
@NSLOOKUP -type=ptr %IP%

How To Ask Questions The Smart Way

Report •

December 16, 2010 at 07:41:36
There are actually versions of "dig" available for Windows, but you are correct to say that only "nslookup" is native to it. No excuse - I actually failed to notice that this was a Windows batch file rather than a UNIX shell script.

If I actually wanted this functionality I wouldn't use a batch file - I'd knock up a quick C# program to do the job.

Report •

Related Solutions

December 16, 2010 at 08:04:39
Yeah, even the Win32 DnsQuery is pretty easy to use, and PowerShell gives you access to the .NET DNS functions. Really, batch script / VBScript are really the wrong languages to use.

How To Ask Questions The Smart Way

Report •

Ask Question