1.

Solve : Hostname to nslookup via batch file?

Answer»

Hello,

What i would like to achieve in a batch file:
Hostname resolve to IP address and from the ip address -> nslookup the ip to resolve the hostname from a csv file (Hostname.csv).

in csv file will contain only the hostname -> Hostname.csv
and the result output tab should contain:
Hostname | ip address | NSlookup hostname -> result.csv

Thanks
Hi 
Can you provide us an example of your input csv file ?
How is the file constructed, that is, what is the delimiter ?
So, your PROBLEM how to get the ip adress from the hostname ?Hi,

Below is somewhat im trying

echo off
for /f %%i in (location of file\hostname.csv) do Call :StartPing %%i
goto :eof

:StartPing
PING %1 -N 1| FIND /i "TTL" > nul && goto Success
PING %1 -n 1| FIND /i "timed" > nul && goto Timedout
PING %1 -n 1 -w 400 | FIND /i "TTL" > nul || goto ErrorMsg
goto :EOF

:Success
for /F "tokens=3" %%a in ('ping %1 ^| find /i "TTL"') do set Address=%%a
for /F "tokens=2" %%a in ('ping -a %Address::=% ^| find /i "pinging"') do set HostName=%%a

set IPAddress=%Address::=%
echo %1, %IPAddress%,%Hostname%

for /f "tokens=2" %%a in ('nslookup %IPAddress% ^| find /i "Name: " ') do set "nsNAME=%%a"
echo "%nsname%"

echo %1, %IPAddress%,%Hostname% >> location of file Results.csv
goto :EOF

:Timedout
Echo %1, Request timed out.
Echo %1, Request timed out. >> location of file Results.csv
goto :EOF

:ErrorMsg
Echo %1, Ping request could not find host.
Echo %1, Ping request could not find host. >> Results.csv
goto :EOF

im stuck with nslookup export

delimiter -> Hostname;ip adress;nslookup hostname (output should have this result altogther)

hostname.csv -> are simply a list with hostname e.g computer 1
                                                                             computer 2

Thanks for the big HELP.



Discussion

No Comment Found