bat实现从内到外的网络检测

bat 实现从内到外的网络检测

@ECHO OFF
cd/d %~dp0
title 网络测试
SET SJ=%RANDOM%/327
if not exist "folder\log\networkrn\" (MD folder\log\networkrn\)
set log=folder\log\networkrn\%date:~0,3%%date:~5,2%%date:~8,2%%sj%.log
@mode con lines=32 cols=100
rem 回送地址
set ip1=127.0.0.1
rem ip地址

for /f "tokens=16" %%i in ('ipconfig ^|find /i "ipv4"') do set ip2=%%i
if "%ip2%"=="" (goto xp1) else goto 2
:xp1
for /f "tokens=15 " %%i in ('ipconfig ^|find /i "ipv4"') do (
set ip2=%%i
if "%ip2%"=="" (goto xp2) else goto 2
)
:xp2
for /f "tokens=15 " %%i in ('ipconfig ^|find /i "IP Address"') do set ip2=%%i
rem 网关地址
:2
for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr 默认网关') do set ip3=%%i
if "%ip3%"=="" (goto xpwg) else goto 3
:xpwg
for /f "tokens=2 delims=:" %%i in ('ipconfig^|findstr Gateway') do set ip3=%%i 
if "%ip3%"=="" (goto debug3) else goto 3
:3
cls
rem 外网地址
rem 我的服务器地址
set ip4=119.6.50.218
set ip5=www.baidu.com
rem 到这里结束
echo                                  networkrn
echo.
echo                           ———————————
echo.
echo                             回送地址:%ip1%
echo.
echo                           本机地址:%ip2%
echo.
echo                            网关地址:%ip3%
echo.
echo                            外网地址:%ip4%
echo.
echo                            测试网址:%ip5%
echo.
echo                          ————————————
echo.
Ping/n 3 127.0.0.1 > NUL 
echo 开始测试
cls
echo log:[%time%]startting
echo log:[%time%]pinging %ip1%
ping %ip1% > NUL
if errorlevel 1 (set test1=×  & goto xs) else set test1=√ 
echo log:[%time%]pinging %ip1%:%test1%


echo log:[%time%]pinging %ip2%
ping %ip2% > nul
if errorlevel 1 (set test2=×  & goto xs) else set test2=√
echo [%time%]pinging %ip2%:%test1%



echo log:[%time%]pinging %ip3%
ping %ip3% > NUL
if errorlevel 1 (set test3=×  & goto xs) else set test3=√
echo log:[%time%]pinging %ip1%:%test1%

echo log:[%time%]pinging %ip4%
ping %ip4% > NUL
if errorlevel 1 (set test4=×  & goto xs) else set test4=√
echo log:[%time%]pinging %ip4%:%test1%

echo log:[%time%]pinging %ip5%
ping %ip5% > nul
if errorlevel 1 (set test5=×  & goto xs) else set test5=√
echo log:[%time%]pinging %ip5%:%test1%
:xs
if "%test1%"=="" (set test1=?)
if "%test2%"=="" (set test2=?)
if "%test3%"=="" (set test3=?)
if "%test4%"=="" (set test4=?)
if "%test5%"=="" (set test5=?)
cls
echo √代表成功
echo ×代表失败
echo ? 代表未测试
echo                        测试结果
echo ——————————————————————
echo.
echo                      回送地址:%test1%            
echo.
echo                      本机ip:%test2%            
echo.
echo                      网关ip:%test3%           
echo.
echo                      外网ip:%test4%
echo.
echo                      具体网址:%test5%                  
echo.
echo ——————————————————————
if %test1%==×  (goto hs)
if %test2%==×  (goto bip)
if %test3%==×  (goto wg)
if %test4%==×  (goto gw)
if %test5%==×  (goto ww)
goto 3
:hs
if exist "failed1.txt" (del failed1.txt & echo 问题依然复现)
echo.
echo 检测出了新问题(ping不通回送地址)
echo 解决方案:
echo 试试重装TCP/IP协议看看
pause

exit
:bip
if exist "failed1.txt" (del failed1.txt & echo 已修复无法ping通回送地址地址问题)
echo 检测出了新问题(ping不通本机ip)
echo 问题导致原因:
echo 网卡或Modem存在问题
echo ip设置可能出现问题
echo 网络可能断开
echo 建议:
echo 将ip设置为自动
pause
exit
:wg
if exist "failed1.txt" (del failed1.txt & echo 已修复无法ping通回送地址地址问题)
if exist "failed2.txt" (del failed2.txt & echo 已修复无法ping通本机ip问题)
echo.
echo 检测出了新问题(ping不通网关)
echo 可能导致的原因(只说几条):
echo 网络因设备间的时延太大
echo IP地址分配问题,内网ip冲突
echo 部分端口不允许用户ping,请自行ping外网ip测试
echo 解决方案:
echo 1.联系网络供应商
echo 2.设置ip自动分配
pause
exit
:gw
echo.
if exist "failed1.txt" (del failed1.txt & echo 已修复无法ping通回送地址地址问题)
if exist "failed2.txt" (del failed2.txt & echo 已修复无法ping通本机ip问题)
if exist "failed3.txt" (del failed3.txt & echo 已修复无法ping通网关ip问题)
echo 检测出了新问题(ping不通外网)
echo 可能导致的原因:
echo 网络设置有问题(lsp等)
echo 确实存在本地网络问题
echo 解决方案:
echo 联系网络供应商
pause
exit
:ww
echo.
if exist "failed1.txt" (del failed1.txt & echo 已修复无法ping通回送地址地址问题)
if exist "failed2.txt" (del failed2.txt & echo 已修复无法ping通本机ip问题)
if exist "failed3.txt" (del failed3.txt & echo 已修复无法ping通网关ip问题)
echo 检测出了新问题(ping不通百度)
echo 可能导致的原因:
echo 网络设置有问题(dns,lsp,hosts等)
echo 确实存在本地网络问题
echo 解决方案:
echo 联系网络供应商
pause
exit

:3
echo.
if exist "failed1.txt" (del failed1.txt & echo 已修复无法ping通回送地址地址问题)
if exist "failed2.txt" (del failed2.txt & echo 已修复无法ping通本机ip问题)
if exist "failed3.txt" (del failed3.txt & echo 已修复无法ping通网关ip问题)
if exist "failed4.txt" (del failed4.txt & echo 已修复无法ping通外网问题)
echo 程序没有发现问题 如果有
echo 如果有
echo 我猜时间没设置对或者lsp,host存在问题
echo 建议:
echo 2.手动cmd重置lsp,清空hosts,重置时钟
echo 3.软件冲突
echo 4.ip,dns设置问题
pause
exit



  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

温辉wh

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

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

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

打赏作者

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

抵扣说明:

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

余额充值