I am trying to ping a list of machines, do an nslookup on the ip addresses, then if hostname is same as original hostname, read from another txt file to output possible location of hostname.
this is my hh.bat script:
@echo Off
@cls
if '%1'=='' GOTO Syntax
echo Running Script and Saving Results to Results.CSV
echo Script Run %date% %time% >> Results.csv
for /F %%i in (%1) 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
: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::=%
nslookup %IPAddress% | find /i "Name" do set nsNAME=
echo %1, %IPAddress%,%Hostname%
echo %1, %IPAddress%,%Hostname% >> Results.csv
goto :EOF
:Timedout
Echo %1, Request timed out.
Echo %1, Request timed out. >> Results.csv
:ErrorMsg
Echo %1, Ping request could not find host.
Echo %1, Ping request could not find host. >> Results.csv
goto :EOF
:Syntax
echo . . .
goto :EOF
:EOF
echo this is the END OF FILE
pause
and this is my host.txt file
Computer1
and this is the list of locations - home.txt
ipaddress - 2G
either ip or hostname... i don't know
hostname - 2D
i am struggeling to do the NSLookup part, and have no idea how to read from the home.txt once nslookup is successfull and echo on the location line.
any suggestions or ideas?