所以这是我目前得到的,老天爷啊,我不能让它正常工作,也就是说,当我的互联网在为 google.com 设置的一段时间后断线时,它在重新连接方面并不是很可靠,也许有人有更复杂/更可靠的方法,已经运行了 2 次,如图所示>
@echo
:Loop
GOTO :pingtest
:pingtest
timeout /t 100
ping -n 400 www.google.com
if errorlevel 1 GOTO :fail
if not errorlevel 1 GOTO :success
:fail
echo Sorry, you have failed the test, Reconnecting to the Internet.
netsh interface set interface "Internet Source" Disable
netsh interface set interface "Internet Source" Enable
:success
echo You have passed the test and are Connected to the Internet!
GOTO :pingtest 2
:pingtest 2
timeout /t 100
ping -n 400 www.google.com
if errorlevel 1 GOTO :fail2
if not errorlevel 1 GOTO :success2
:fail2
echo Sorry, you have failed the test, Reconnecting to the Internet.
netsh interface set interface "Internet Source" Disable
netsh interface set interface "Internet Source" Enable
:success2
echo You have passed the test and are Connected to the Internet!
GOTO :Loop
非常感谢,并希望有两组像上面的例子一样的测试,然后进行循环检查,谢谢
答案1
您可以尝试使用此批处理脚本来检测您是否已连接到互联网
获得额外 IP 即可获得您的外部 IP:检查是否已连接到互联网
@echo off
Title Checking Internet Connection & Mode 70,4 & color 0B
::-------------------------------------------------------------------------------------
REM First We Check The Status Of The Internet Connection
Call :Check_Connection
::-------------------------------------------------------------------------------------
:Main
Title Your Extrenal IP Address
Mode 50,4 & Color 0A
for /f "tokens=2 delims=: " %%A in (
'nslookup myip.opendns.com. resolver1.opendns.com 2^>NUL^|find "Address:" ^| findstr /v "208.67.222.222" '
) Do (
If "%%A" NEQ "127.0.0.1" (
set "ExtIP=%%A"
) else (
Color 0C & echo(
echo No internet connection !
)
)
echo(
If defined ExtIP (
echo You are connected to the internet !
echo Your External IP is : %ExtIP%
)
Pause>nul & Exit
::-------------------------------------------------------------------------------------
:Check_Connection
Title Checking Internet Connection ...
SetLocal EnableDelayedExpansion
Mode 50,3 & Color 0B
echo(
echo( Please Wait... Checking Internet Connection ...
Timeout /T 1 /NoBreak>nul
Ping www.google.nl -n 1 -w 1000>nul
cls
echo(
if [!errorlevel!] EQU [1] (
Color 0C & set "internet=Not Connected To Internet"
echo( Connection Status : !Internet!
CMD /C %SystemRoot%\system32\msdt.exe ^
Skip TRUE -path %Windir%\diagnostics\system\networking -ep NetworkDiagnosticsPNI
Timeout /T 1 /NoBreak>nul & Goto Check_Connection
) else (
Color 0A & set "internet=Connected To Internet"
echo( Connection Status : !Internet!
Timeout /T 1 /NoBreak>nul & Goto Main
)
EndLocal
::-------------------------------------------------------------------------------------