批处理 ping命令
代码:
@echo off
Rem 在win7下以管理员身份运行。IP00为十层机房网关 IP01是IaaS管理平台所在机器 IP02是证明该程序是正确的
setlocal enabledelayedexpansion
set IP00=172.21.48.1
set IP01=172.21.35.15
set IP02=192.16.1.1
Rem 以下是十层机房内机器IP
set IP1=172.21.48.118
set IP2=172.21.48.123
set IP3=172.21.48.124
set IP4=172.21.48.126
set IP5=172.21.48.127
set IP6=172.21.48.142
Rem set timeout=Request timed out.
set timeout=请求超时。
for %%i in (%IP00% %IP01% %IP02% %IP1% %IP2% %IP3% %IP4% %IP5% %IP6%) do (
set result=true
ping %%i -n 1 | find “%timeout%”>%temp%MyTempPingFile.txt
for /F “delims=” %%j in (%temp%MyTempPingFile.txt) do set result=false
if !result!==true (
echo ping %%i 通!) else (
echo ping %%i 不通!
)
)
del %temp%MyTempPingFile.txt
pause