Ping测试使用BAT文件 - 与ERRORLEVEL麻烦 [英] Ping Test Using Bat File - Trouble with errorlevel

查看:1206
本文介绍了Ping测试使用BAT文件 - 与ERRORLEVEL麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用批处理文件建立一个局域网ping测试。在code我对网站的伟大工程,但它对于本地IP地址的行为奇怪。我正在运行的3台电脑,我知道的IP地址的ping测试。无论我拔出其中一个,当我运行低于code,在%ERRORLEVEL%是所有三台电脑始终为0。像它在网站上它永远不会等于1。我该如何解决?

 关闭@echo
CLS
设置名称IP地址= www.google.com
PING%名称IP地址%-n 1
 拨打:Ping​​Test设置名称IP地址= www.yahoo.com
PING%名称IP地址%-n 1
 拨打:Ping​​Test设置名称IP地址= www.unabletoping.com
PING%名称IP地址%-n 1
 拨打:Ping​​Test暂停>空值
出口:Ping​​Test
IF%ERRORLEVEL%EQU 1(回声服务器脱机),其他(GOTO:EOF)


解决方案

当您在子网ping一个非入店地址,你会得到一个无法访问的答案,以及发送,1挤得收到0数据包丢失1包。 ERRORLEVEL未设置。

当你ping一个非入店地址你的子网,你会得到一个超时的答案,有送1包,接收数据包0,1包丢失。 ERRORLEVEL设置。

和,您可以ping有效机床,丢失的数据包,并得到一个错误级别

和,您可以ping一个有效/无效机,得到TTL过期,没有得到错误级别

更好,检查ping响应的内容。

 平-n 1 192.168.1.1 |找到TTL => NUL
如果错误级别1(
    回声主机不可达
)其他(
    回声主机访问

I am working on setting up a LAN ping test using a batch file. The code i have works great for websites but it acts strange for local IPs. I am running the ping test on 3 computers that i know the IPs of. No matter which one i unplug, when i run the code below, the %errorlevel% is always 0 on all three computers. It never equals to 1 like it does on a website. How can i resolve this?

@echo off
cls
Set IPaddress=www.google.com
PING %IPaddress% -n 1
 call :PingTest

Set IPaddress=www.yahoo.com
PING %IPaddress% -n 1
 call :PingTest

Set IPaddress=www.unabletoping.com
PING %IPaddress% -n 1
 call :PingTest

pause > null
exit

:PingTest
IF %errorlevel% EQU 1 (echo "Server is Offline") else (GOTO:EOF)

解决方案

When you ping an non accesible address in your subnet, you get an "unreachable" answer, with 1 packet sent, 1 packed received, 0 packets lost. Errorlevel is not set.

When you ping an non accesible address out of your subnet, you get a "timeout" answer, with 1 packet sent, 0 packet received, 1 packet lost. Errorlevel is set.

And, you can ping an active machine, lost packets and get an errorlevel

And, you can ping an active/inactive machine, get TTL expired and get no errorlevel

Better, check for content of ping response.

ping -n 1 192.168.1.1 | find "TTL=" >nul
if errorlevel 1 (
    echo host not reachable
) else (
    echo host reachable
)

这篇关于Ping测试使用BAT文件 - 与ERRORLEVEL麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆