Question : get server Names

with the code from http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_24141480.html, do you think it could pull the machine names as well?

Answer : get server Names

In the example it is logging the netBIOS name. If you want the fully qualified DNS name use this line.

    echo !DNSName!,!IP!,!Status:~1,-1!>>%LogFile%
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
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% 
Open in New Window Select All
Random Solutions  
 
programming4us programming4us