假设你的宽带连接已在网络连接中建立好, 仅在第一次运行时, 需要输入宽带的配置信息, 以后将自动读取已保存的配置(在文件%windir%\autoADSL.cmd内)进行自动连接, 无需再次干预- @echo off
- if "%1" == "h" goto begin
- (set /p show=需要显示小窗口界面吗^(y/n^)[直接回车=不显示]:)
- if /i "%show:~0,1%" equ "y" goto begin
- mshta vbscript:createobject("wscript.shell").run("%~nx0 h",0)(window.close)&&exit
- :begin
-
- @echo off&setlocal enabledelayedexpansion
- chcp 936 & cls & rem 后面的的判断全以中文代码页936输出为准
- if not exist "%windir%\autoADSL.cmd" (
- start Control netconnections
- echo ===== 输入宽带连接配置信息并保存到文件 %windir%\autoADSL.cmd =====&echo.
- (set /p ADSL_Name=请输入宽带连接在"网络连接"中的名称^(通常就是宽带连接或ADSL等^):)
- (set /p ADSL_Username=请输入宽带连接的用户名:)
- (set /p ADSL_password=请输入宽带连接的密码:)
- echo rasdial.exe !ADSL_Name! !ADSL_Username! !ADSL_password!>%windir%\autoADSL.cmd
- )
- rem echo 请将有效的宽带连接快捷方式拖到此窗口 或 人工输入它的全路径
- rem echo 如果不想用快捷方式来连接, 请直接回车
- rem (set /p ADSL_link=宽带连接快捷方式全路径:) & rem 宽带连接的快捷方式全路径若包含有空格, 请用双引号对括起
- (set fn=%windir:~0,2%\~netmp)
-
- cls & mode con lines=2 cols=54
- :loop
- (ipconfig/all>!fn!)
- (set foundLC=false)&(set foundLCPA=false)&(set LCC=true)&(set LCPA=)&(set PPP_WAN=false)
- for /f "delims=" %%i in (!fn!) do (
- (set ln=%%i) & rem echo !ln!
- (set ln=!ln: =!) & (set ln=!ln:*本地连接:=本地连接:!)
- if "!ln:~0,5!" equ "本地连接:" (
- (set foundLCPA=false)&(set foundLC=true)
- )
- if /i "!ln:~0,10!" equ "MediaState" (
- (set ln=!ln:*disconnected=disconnected!)
- if /i "!ln:~0,12!" equ "disconnected" (
- if /i "!foundLC!" equ "true" if /i "!foundLCPA!" equ "false" (set LCC=false)&rem(set /p=╳本地连接被断开<nul)
- )
- )
- if /i "!ln:~0,15!" equ "PhysicalAddress" (
- if /i "!foundLC!" equ "true" if "!LCPA!" equ "" (
- (set foundLCPA=true)&(set ln=!ln:*:=!)&(set LCPA=!ln:~0,17!)
- )
- )
- if /i "!ln:~0,3!" equ "PPP" (set PPP_WAN=true)
- (set ln=!ln:*:=!)
- if /i "!ln:~0,3!" equ "WAN" (set PPP_WAN=true)
- )
- if /i "!foundLC!" equ "false" (set LCC=false)
- cls
- if !LCC! neq !LCC0! (set LCC0=!LCC!)&if /i "!LCC!" equ "false" (set /p=<nul) else (set /p=<nul)
- if !PPP_WAN! neq !PPP_WAN0! (set PPP_WAN0=!PPP_WAN!)&if /i "!PPP_WAN!" equ "false" (set /p=<nul) else (set /p= <nul)
- if /i "!PPP_WAN!" equ "true" (set sgn=╬═╬本地和宽带) else (set sgn=╩本地)
- if /i "!LCC!" equ "false" (
- (color cf)&(title ╳本地连接^(!LCPA!^)被断开) & echo ╳本地连接^(!LCPA!^)被断开
- if /i "!foundLC!" equ "false" (color 3f)&(title ?本地连接^(!LCPA!^)不存在或停用) & echo ?本地连接^(!LCPA!^)不存在或停用
- (set PPP_WAN=false)
- ) else (
- (title !sgn!连接^(!LCPA!^)已连接上) & (set /p=!sgn!连接^(!LCPA!^)已连接上<nul)
- if /i "!PPP_WAN!" equ "true" (color 2f) else (color 9f)
- if /i "!PPP_WAN!" equ "false" (
- if exist %windir%\autoADSL.cmd (
- (call %windir%\autoADSL.cmd>!fn!)
- for /f "delims=" %%i in (!fn!) do (
- (set ln=%%i)
- if "!ln:~0,3!" equ "已连接" (color 2f)&(set PPP_WAN=true)&(set /p=宽带连接已重新连上<nul)
- )
- )
- rem !ADSL_link!
- )
- )
- ping -n 2 127.1>nul
- goto loop
复制代码
[ 本帖最后由 neorobin 于 2009-12-9 17:26 编辑 ] |