当前位置:首页 > Windows程序 > 正文

Windows批处理:自动检查网络连通性

2021-03-28 Windows程序

  检测网络连通性我用的是丛远到近的方法,即外网——网关——内网——本机,,脚本的实现也是根据这个顺序用ping来检测,为提高检测速度,这里我只ping2次,各位可以根据自己的需要进行修改。

  使用方法大神们都会的... 复制代码,另存为.bat文件后执行。


@echo off color 2F title 网络连通性检测 echo. echo. ping -n 2 223.5.5.5>%temp%\1.ping & ping -n 2 223.6.6.6>>%temp%\1.ping    ::ping阿里公共DNS findstr "TTL" %temp%\1.ping>nul if %errorlevel%==0 (echo     √ 外网正常) else (echo     × 外网不通)         ::根据返回值输出 echo. ping -n 2 192.168.1.1>%temp%\2.ping findstr "TTL" %temp%\2.ping>nul if %errorlevel%==0 (echo     √ 网关正常) else (echo     × 网关不通) echo. ping -n 2 192.168.1.2>%temp%\3.ping findstr "TTL" %temp%\3.ping>nul if %errorlevel%==0 (echo     √ 内网正常) else (echo     × 内网不通) echo. ping -n 2 127.0.0.1>%temp%\4.ping findstr "TTL" %temp%\4.ping>nul if %errorlevel%==0 (echo     √ TCP/IP协议正常) else (echo     × TCP/IP协议异常) if exist %temp%\*.ping del %temp%\*.ping                ::删除缓存文件 echo. echo. pause


效果如下:

技术分享

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69056.html