Following guide shows how you can query IP addresses of servers listed in a text file by using NSLOOKUP or Ping.
NSLOOKUP:
- Create a batch file with following content.
@echo off
for /f %%a in (servers.txt) do call :process %%a
goto :eof
:process
set srv=%1
for /f "tokens=2" %%b in ('nslookup -type=A %srv%^|find /i "Address"') do echo %srv% - %%b >> results.txt
-
Create a text file called servers.txt and list each server name on a separate line.
-
Result will list each server on a separate line along with it's ip address in a file: results.txt
--
PING:
You can do the same thing by using PING command, following is a batch file:
@echo off
setlocal enabledelayedexpansion
set OUTPUT_FILE=results.txt
>nul copy nul %OUTPUT_FILE%
for /f %%i in (servers.txt) do (
set SERVER_ADDRESS=ADDRESS N/A
for /f "tokens=1,2,3" %%x in ('ping -n 1 %%i ^&^& echo SERVER_IS_UP') do (
if %%x==Pinging set SERVER_ADDRESS=%%y
if %%x==Reply set SERVER_ADDRESS=%%z
if %%x==SERVER_IS_UP (set SERVER_STATE=UP) else (set SERVER_STATE=DOWN)
)
echo %%i [!SERVER_ADDRESS::=!] is !SERVER_STATE!
echo %%i [!SERVER_ADDRESS::=!] is !SERVER_STATE! >>%OUTPUT_FILE%
)