检查特定的无线连接是否与批处理文件相关联

时间:2015-04-24 15:57:00

标签: batch-file

我是新手,仍在学习,请原谅我的语法。

我要做的是有一个批处理文件来检查是否连接了无线连接.....如果是这样....那么我可以从那里完成代码......

到目前为止我已经

IF netsh interface show interface name="CMP********" Goto :SUCCESS 

IF NOT netsh interface show interface name="CMP*********" Goto :FAIL 

:SUCCESS
ECHO You have an active Internet connection
pause
goto END

:FAIL
ECHO You have an nonactive Internet connection
pause
goto END

:END

我知道这不对,但需要一些帮助。

由于

1 个答案:

答案 0 :(得分:0)

@echo off
:==
set "network_to_check=LAN1:"
:==
set nt=0
setlocal enableDelayedExpansion
for /f "skip=3 delims=" %%$ in ('ipconfig') do (
    set "line=%%$"
    ! echo %%$ >&2

    if "!line:~0,1!" neq " " (
        set /a nt=nt+1
        set _nt!nt!=!line!

    ) else (
        ! echo ----
        for /f %%# in ("!nt!") do (
            ! echo a:%%#
            ! echo --- %%# ---

            set "_nt!nt!=!_nt%%#!  !line!" 

        )   
    )
)

set _nt|find /i "%network_to_check%" >nul 2>nul||(
    echo network not found
    exit /b 1
)

set _nt| find /i "%network_to_check%"|find /i "Media disconnected" >nul 2>nul&&(
    echo disconnected
    exit /b 1
) 

echo connected

endlocal

在开头更改网络名称,看看这是否适合您。为了获得更好的结果,请在网络名称末尾设置:

相关问题