-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-hosts.bat
52 lines (43 loc) · 1.1 KB
/
check-hosts.bat
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
40
41
42
43
44
45
46
47
48
49
50
51
52
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:: CURRIE, Matthew
:: 14 Jan 2016
:: Check network host status from list
:: Load a comma delimited list of network hosts to check with ping
:: Format ip_address,description with spaces
:: Usage: check-hosts.bat hosts.cfg
REM %SystemRoot%\system32\ping.exe -n 1 %%a >nul
::
:: DEV NOTES: Careful of DELAYED VARIABLE EXPANSION
echo.
echo Checking for network hosts on LAN per %1
echo.
echo Network Address(s)
echo ------------------
echo.
set ip_address_string="IPv4 Address"
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do (
echo Network Address: %%f
)
echo.
echo Network Hosts
echo -------------
echo.
set host_status=1
set HOST_PASS=1
set HOST_FAIL=0
for /f "tokens=*" %%i in (%1) do (
:: %%i is string
for /f "delims=, tokens=1,2" %%a in ("%%i") do (
set host_status=!HOST_PASS!
ping -n 1 %%a | findstr /I /C:"timed out" /C:"host unreachable" /C:"could not find host" >nul && set host_status=!HOST_FAIL!
if !host_status!==1 (
echo [ OK ] %%b - %%a
) else (
echo [FAIL] %%b - %%a
)
)
)
echo.
pause
ENDLOCAL