网络测试的window bat脚本分析

来源:互联网 发布:柠檬网络电视 | 柠檬tv 编辑:程序博客网 时间:2024/05/20 05:07

测试脚本内容如下:

@echo off:: 设置窗口底色为绿色color 2Ftitle 网络连通性检测echo.echo.ping -n 2 223.5.5.5 > %temp%\1.ping & ping -n 2 223.6.6.6 >> %temp%\1.ping    ::ping阿里公共DNSfindstr "TTL" %temp%\1.ping > nulif %errorlevel%==0 (echo     √ 外网正常) else (echo     × 外网不通)         ::根据返回值输出echo.ping -n 2 192.168.0.1 > %temp%\2.pingfindstr "TTL" %temp%\2.ping > nulif %errorlevel%==0 (echo     √ 网关正常) else (echo     × 网关不通)echo.ping -n 2 192.168.0.3 > %temp%\3.pingfindstr "TTL" %temp%\3.ping > nulif %errorlevel%==0 (echo     √ 内网正常) else (echo     × 内网不通)echo.ping -n 2 127.0.0.1 > %temp%\4.pingfindstr "TTL" %temp%\4.ping > nulif %errorlevel%==0 (echo     √ TCP/IP协议正常) else (echo     × TCP/IP协议异常)::删除缓存文件if exist %temp%\*.ping del %temp%\*.pingecho.echo.pause

相关知识点

D:\>ping -n 2 123.125.114.144>%temp%\1.ping & ping -n 2 180.76.76.76>>%temp%\1.pingD:\>echo %temp%\1.pingC:\Users\000\AppData\Local\Temp\1.ping////查看 PC“环境变量”TEMP%USERPROFILE%\AppData\Local\TempD:\>cat %temp%\1.ping正在 Ping 123.125.114.144 具有 32 字节的数据:来自 123.125.114.144 的回复: 字节=32 时间=2ms TTL=56来自 123.125.114.144 的回复: 字节=32 时间=2ms TTL=56123.125.114.144Ping 统计信息:    数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失),往返行程的估计时间(以毫秒为单位):    最短 = 2ms,最长 = 2ms,平均 = 2ms正在 Ping 180.76.76.76 具有 32 字节的数据:来自 180.76.76.76 的回复: 字节=32 时间=3ms TTL=56来自 180.76.76.76 的回复: 字节=32 时间=3ms TTL=56180.76.76.76Ping 统计信息:    数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失),往返行程的估计时间(以毫秒为单位):    最短 = 3ms,最长 = 3ms,平均 = 3ms///// findstr 命令findstr是Window系统自带的命令,用于查找某路径下指定的一个或多个文件中包含某些特定字符串的行,并将该行完整的信息打印出来,或者打印查询字符串所在的文件名。其用途和用法类似Linux下的grep命令。findstr命令在MS-DOS下使用。D:\>findstr "TTL" %temp%\1.ping来自 123.125.114.144 的回复: 字节=32 时间=2ms TTL=56来自 123.125.114.144 的回复: 字节=32 时间=2ms TTL=56来自 180.76.76.76 的回复: 字节=32 时间=3ms TTL=56来自 180.76.76.76 的回复: 字节=32 时间=3ms TTL=56::错误码errorlevel或称返回码,常见的返回码为01D:\>echo %errorlevel%0D:\>
原创粉丝点击