SETLOCAL ENABLEDELAYEDEXPANSION
Set logfile="C:\Inetpub\wwwroot\20090213_15-06-00.txt"
Set TimeNow=%Time:~0,-6%
Set TimeNow=%TimeNow: =%
Set TimeNow=%TimeNow::=%
REM IF EXIST %LogFile% DEL /f /q %LogFile%
for /f %%c in (servers.txt) do (
Set IP=
Set Status=
Set DNSName=
Set NetBIOSName=
for /f "Tokens=1,2,3 delims=[] " %%p in ('ping -a -n 1 -w 1000 %%c ^| Find /i "Pinging"') do (
Set DNSName=%%q
Set IP=%%r
)
for /f "tokens=1 delims=." %%p in ('echo !DNSName!') do Set NetBIOSName=%%p
IF NOT DEFINED IP Set IP=%%c
for /f "delims=" %%p in ('ping -n 1 -w 1000 %%c') do (
ECHO "%%p" | Find /i "Reply from"
IF NOT ERRORLEVEL 1 Set Status="Online."
ECHO "%%p" | Find /i "Request timed out."
IF NOT ERRORLEVEL 1 Set Status="No response (Offline)."
ECHO "%%p" | Find /i "try again"
IF NOT ERRORLEVEL 1 Set Status="Unknown host (no DNS entry)."
)
echo !NetBIOSName!,!IP!,!Status:~1,-1!>>%LogFile%
{Add your rules here.}
)
ECHO.>>%LogFile%
ECHO ,Ping batch complete %date% %time%>>%LogFile%
|