Windows ping

 

 

 


ping 的 ERRORLEVEL

 

ERRORLEVEL number

Specifies a true condition only if the previous program run by Cmd.exe returned an exit code equal to or greater than Number.

其中一次 ping 成功, ERRORLEVEL 就會 0

Remark

# Remote Linux 測試

iptables -I INPUT -p icmp -j DROP

iptables -D INPUT -p icmp -j DROP

 


ping host timeout vs unreachable

 

When you ping an non accesible address in your subnet, you get an "unreachable" answer,

Errorlevel is not 0.

If the message is "Reply From < IP address >: Destination Host Unreachable," then the routing problem occurred at a remote router,

whose address is indicated by the "< IP address >" field. Use the appropriate utility or facility to check the IP routing table of the router assigned the IP address of < IP address >.

When you ping an non accesible address out of your subnet, you get a "timeout" answer,

Errorlevel is 1.

 


碓認 ping 到

 

方法: pipe the output of the ping command through find to see if the ping had a reply

IP 192.168.88.234 是 ping 不到的, result 會有 "unreachable"

ping -n 2 -w 3000 192.168.88.234 | findstr "TTL" > nul
if "%ERRORLEVEL%" EQU "0" ( echo "Success" & pause > null)