自动检测网络通断(改进版)
引用了网络上的版本加以改进1、可以指定PING的IP,或者默认PING网关(自动获取)
2、PING www.baidu.com,以验证网络连接状况
3、会用屏幕的颜色变化反映PING结果,如果是绿色表示是通的,红色表示不正常
@echo off
title 网络连通测试
:a
chcp 65001>nul
call :select "IPV4 Address" "ip"||call :select "IP Address" "ip"
call :select "Physical Address" "mac"
call :select "Default Gateway" "gateway"
call :select "DNS Servers" "dns"
call :select "Description" "netcard"
:: 演示效果
chcp 936>nul
setlocal ENABLEDELAYEDEXPANSION
echo.
echo.===============================================================
echo.
echo. 欢 迎 使 用 网 络 配 置 信 息 查 看 器
echo.
color a
echo.
echo 本机IP:%ip%
echo 本机MAC:%mac%
echo 本机DNS:%dns%
echo 网关IP:%gateway%
echo 网卡名称:%netcard%
echo.
REM PingSite表示外部网络的参考网址
REM LanIP表示本地网络的网关
REM set PingSite=www.baidu.com
set LanIP=%gateway%
set /p PingSite=请输入要检查的网址或者IP【如:%gateway%】:
if NOT DEFINED PingSite set PingSite=www.baidu.com
echo.
echo.===============================================================
echo.
echo. 即将Ping %LanIP%
echo.
REM ping %LanIP% -n 1 -l 1 >nul 2>nul
ping %LanIP% |find "TTL"
if %ERRORLEVEL% EQU 0 (
REM echo.ERRORLEVEL=%ERRORLEVEL%
color 27
echo.
echo 哦-----本地网络可以访问
REM ping %PingSite% -n 1 -l 1 >nul 2>nul
echo.
echo.
echo.===============================================================
echo.
echo. 即将Ping %PingSite%
echo.
call :PingSiteProc
) else (
color 47
echo.
echo 哦----本地网络倒闭
echo 坏了-----网络彻底瘫痪了
echo.
)
REM echo.
REM echo.===============================================================
REM echo.
REM echo. 即将Ping %PingSite%
REM echo.
REM ping %web%||echo.&&echo ◎◎◎◎◎◎◎◎◎◎◎◎◎&&color 47&&echo.&&echo 网络不通,请检查&&echo.&&echo ◎◎◎◎◎◎◎◎◎◎◎◎◎
echo.
echo.===============================================================
timeout 5 >nul
cls
goto a
REM pause>nul
REM goto :eof
:PingSiteProc
ping %PingSite% |find "TTL"
if %ERRORLEVEL% EQU 0 (
color 27
echo.
echo 耶-----%PingSite% 可以访问
echo 真爽-----网络畅通无阻
REM ^G表示Ctrl+G
REM echo ^G
) else (
REM echo.ERRORLEVEL3=%ERRORLEVEL%
color 47
echo 唔----%PingSite% 不能访问!
echo 不好-----网络闭关锁国了
echo.
)
goto :eof
::**************************************************************
:: 解析ipconfig命令输出通用函数
::**************************************************************
:select
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:%1') do if not "!%~2!" == "" set "%~2=%%i"
goto :eof
支持原创 多网卡识别异常 感谢分享 感谢分享 收藏一个玩玩先 感谢分享 谢谢分享 很好的脚本,我的电脑上运行却是乱码 谢谢分享 用ANSI编码格式,显示正常了,感谢!! 感谢分享 感谢分享 感谢分享 回复下载 感谢分享 感谢分享,支持一下 本帖最后由 kedion 于 2024-3-12 15:03 编辑
@echo off
Set host=music.163.com
:check
ping -n 4 %host%
IF ERRORLEVEL 1 goto check
IF ERRORLEVEL 0 goto startConnect
:startConnect
cls
Set ip=
For /f "skip=1 tokens=2 delims=[" %%a in ('ping%host%') do (
For /f "tokens=1 delims=]" %%b in ("%%a") do (
Set ip=%%b
)
)
cd D:\Music
node app.js -f %ip%
pause
我用这个进行检测的,忘记在哪里看到的例子进行更改的了,给网易云解锁脚本用的有网的时候自动执行后边的脚本,没网就一直重试,直到有网为止 谢谢分享! 頂,謝謝樓主的勞動和分享!數據會記錄每個信息對網絡的奉獻! 感谢热心提供分享! 分享就是是好朋友 本帖最后由 1801403 于 2024-3-11 23:41 编辑
是不是我的姿势不对啊?DNS和网关都没获取成功啊。不管是IPV4还是IPV6,都不对啊。显示也不完全。。。直接按回车,也不会ping百度。。。
赞,谢谢分享。 感谢分享 感谢分享 感谢楼主的分享、一会空闲了可以试试 感谢分享 1801403 发表于 2024-3-11 23:38
是不是我的姿势不对啊?DNS和网关都没获取成功啊。不管是IPV4还是IPV6,都不对啊。显示也不完全。。。直接 ...
可能系统配置中存在多网卡配置,比如虚拟网卡,这个默认只取了第1个,你用IPCONFIG /ALL看看就知道了 感谢分享 不行,网络正常 ,就一个网卡,回车 检测完居然说没有网络。
页:
[1]
2