关于几行批处理命令判断网络问题所在(优化版)

修复了n项问题,加入了延迟数值记录

@echo off
cd/d %~dp0
set log=pinglog.log
title 网络诊断工具
echo pinging 127.0.0,1
ping 127.0.0.1 > ping.txt
if errorlevel 1 (set error1=0 & set test0=×  & goto jg) else set test0=√
for  /f  "skip=11 delims="  %%a  in  (ping.txt)  do  (
set  ms1=%%~a
goto ms1
)
:ms1
set ms1=%ms1:~44,-1%
echo %ms1%
rem 获取自身和网关ip
:1
for /f "tokens=16" %%i in ('ipconfig ^|find /i "ipv4"') do (
set ip1=%%i
if "%ip1%"=="" (goto xp1)
goto 2
)
:xp1
for /f "tokens=15 " %%i in ('ipconfig ^|find /i "IP Address"') do (
set ip1=%%i
goto 2
)
:2
rem from batchhome
rem b
for /f "tokens=15" %%i in ('ipconfig ^| find /i "默认网关" ^| find /i "172"') do set gateway=%%i
if "%gateway%"=="" (goto wgb) else goto test1
rem from batchhome
:wgb
rem a类
for /f "tokens=15" %%i in ('ipconfig ^| find /i "默认网关" ^| find /i "192"') do set gateway=%%i
if "%gateway%"=="" (goto wgc) else goto test1
:wgc
rem c类
for /f "tokens=15" %%i in ('ipconfig ^| find /i "默认网关" ^| find /i "10"') do set gateway=%%i
if "%gateway%"=="" (goto xpwg) else goto test1
:xpwg
for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr Gateway') do set ip2=%%i &goto test1
:test1
echo.
echo get var bat ip2=%ip2%>>%log%
echo pinging %ip1% 
ping %ip1% > ping.txt
if "%ip1%"=="" (set error1=1 & set test1=× & set test2=? & set test3=? & goto jg)
if "%errorlevel%"=="1" (set error1=1 & set test1=× & set test2=? & set test3=? & goto jg) else set test1=√
for  /f  "skip=11 delims="  %%a  in  (ping.txt)  do  (
set  ms2=%%~a
goto ms2
)
:ms2
set ms2=%ms2:~44,-1%
echo %ms2%
echo pinging %ip2% 
ping %ip2% > PING.TXT

for  /f  "skip=11 delims="  %%a  in  (ping.txt)  do  (
set  ms3=%%~a
goto ms3
)
:ms3
set ms3=%ms3:~44,-1%
echo %ms3%
if "%ip2%"=="" (set error1=2  & set test2=× & set test3=? & goto jg)
if "%errorlevel%"=="1" (set error1=2 & set test2=× & set test3=? & goto jg) else set test2=√
echo pinging www.baidu.com
ping www.baidu.com > ping.txt
for  /f  "skip=11 delims="  %%a  in  (ping.txt)  do  (
set  ms4=%%~a
goto ms4
)
:ms4
set ms4=%ms4:~47,-1%
echo %ms4%
echo %errorlevel%
if "%errorlevel%"=="1" (set error1=3 & set test3=× &goto jg) else set test3=√ & set error1=5
goto jg
:jg
cls
echo √代表成功
echo ×代表失败
echo ? 代表未测试
echo                        测试结果
echo ——————————————————————
echo.
echo    回送地址:%test0%            平均延迟:%ms1%
echo.
echo    本机ip:%test1%              平均延迟:%ms2%
echo.
echo    网关直连:%test2%            平均延迟:%ms3%
echo.
echo    公网:%test3%               平均延迟:%ms4%
echo.
echo ——————————————————————
if %error1%==0  (goto hs)
if %error1%==1  (goto bip)
if %error1%==2  (goto wg)
if %error1%==3  (goto gw)
goto 3
:hs
echo.
echo 检测出了问题(ping不通回送地址)
echo 解决方案:
echo 试试重装TCP/IP协议看看
pause
exit
:bip
echo 检测出了问题(ping不通本机ip)
echo 问题导致原因:
echo 网卡或Modem存在问题
echo ip设置可能出现问题
echo 网络可能断开
echo 建议:
echo 将ip设置为自动
pause
exit
:wg
echo.
echo 检测出了问题(ping不通网关)
echo 可能导致的原因(只说几条):
echo 网络因设备间的时延太大
echo IP地址分配问题,内网ip冲突
echo 部分端口不允许用户ping,请自行ping外网ip测试
echo 解决方案:
echo 1.联系网络供应商
echo 2.设置ip自动分配
pause
exit
:gw
echo.
echo 检测出了问题(ping不通外网)
echo 可能导致的原因:
echo 网络设置有问题(dns,lsp等)
echo 确实存在本地网络问题
echo 解决方案:
echo 使用重置网络bat
echo 联系网络供应商
pause
exit
exit
:3
echo.
echo 程序没有发现问题 如果有
echo 如果有
echo 我猜时间没设置对或者lsp,host存在问题(也不应该啊,试试网络修复bat)
echo 建议:
echo 1.使用重置网络.bat
echo 2.手动cmd重置lsp,清空hosts,重置时钟
echo 3.软件冲突
echo 4.ip,dns设置问题
pause
exit
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

温辉wh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值