资源描述
将下面的代码拷贝到文本文件内,并将文件格式修改为Bat批处理文件。(注:无线热点需要无线网卡支持此功能)
@echo off
title --网络IP自动设置 --
MODE con: COLS=80 lines=30
color 0b
:main
cls
echo 请按提示操作
echo.
echo 请先选择您的操作系统
echo.
echo Win7及以下系统,请按1
echo Win8的各位亲们,请按2
echo.
set /p windows= 您的选择:
echo.
if "%windows%"=="1" goto setWin7
if "%windows%"=="2" goto setWin8
:main1
cls
echo.
echo 请选择您需要连接的网络
echo.
echo 连接办公室无线,请按 1
echo 连接办公室有线,请按 2
echo 连接办公室娱乐,请按 3
echo 连接办公室无线,请按 1
echo 连接办公室有线,请按 2
echo 连接办公室娱乐,请按 3
echo 连接家庭无线,请按 4
echo 连接家庭有线,请按 5
echo 开启无线共享,请按6
echo 要退出请按 7
echo.
@rem 上一句是空一行
set /p choice= 您的选择:
echo.
if "%choice%"=="1" goto ip1
if "%choice%"=="2" goto ip2
if "%choice%"=="3" goto ip3
if "%choice%"=="4" goto ip4
if "%choice%"=="5" goto ip5
if "%choice%"=="6" goto ip6
if "%choice%"=="7" goto test
:setWin7
set "onlinetype1=本地连接"
set "onlinetype2=无线网络连接"
goto main1
:setWin8
set "onlinetype1=以太网"
set "onlinetype2=Wi-Fi"
goto main1
:ip1
echo 办公室无线自动设置开始....
echo 正在设置IP及子网掩码
cmd /c netsh interface ip set address name=%onlinetype2% source=static addr=10.102.3.192 mask=255.255.0.0 gateway=10.102.1.254 gwmetric=1
echo 正在设置DNS服务器
cmd /c netsh interface ip set dns name=%onlinetype2% source=static addr=202.96.128.86 register=PRIMARY
@rem 以上这句为设置DNS为202.96.128.86
echo 正在设置DNS服务器
cmd /c netsh interface ip add dns name=%onlinetype2% addr=202.96.128.166
@rem 以上这句为设置DNS为202.96.128.86
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:ip2
echo 办公室有线自动设置开始....
echo 正在设置IP及子网掩码
cmd /c netsh interface ip set address name=%onlinetype1% source=static addr=172.17.7.5 mask=255.255.255.0 gateway=172.17.7.1 gwmetric=1
echo 正在设置DNS服务器
cmd /c netsh interface ip set dns name=%onlinetype1% source=static addr=172.17.100.1 register=PRIMARY
@rem 以上这句为设置DNS为172.17.100.13
echo 正在设置DNS服务器
cmd /c netsh interface ip add dns name=%onlinetype1% addr=218.2.135.1
@rem 以上这句为设置DNS为172.17.100.1
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:ip3
echo 办公室娱乐自动设置开始....
echo 正在设置IP及子网掩码
cmd /c netsh interface ip set address name=%onlinetype1% source=static addr=172.17.7.229 mask=255.255.255.0 gateway=172.17.7.1 gwmetric=1
echo 正在设置DNS服务器
cmd /c netsh interface ip set dns name=%onlinetype1% source=static addr=172.17.100.22 register=PRIMARY
@rem 以上这句为设置DNS为172.17.100.225
cmd /c netsh interface ip add dns name=%onlinetype1% addr=218.2.135.1
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:ip4
echo IP自动设置开始....
echo 正在连接无线网络“505”
netsh wlan connect interface=%onlinetype2% name="505"
echo 自动获取IP地址....
netsh interface ip set address name = %onlinetype2% source = dhcp
echo 自动获取DNS服务器....
netsh interface ip set dns name = %onlinetype2% source = dhcp
@rem 设置自动获取IP
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:ip5
echo 家庭有线自动设置开始....
echo 正在设置IP及子网掩码
cmd /c netsh interface ip set address name=%onlinetype1% source=static addr=192.168.1.199 mask=255.255.255.0 gateway=192.168.1.1 gwmetric=1
echo 正在设置DNS服务器
cmd /c netsh interface ip set dns name=%onlinetype1% source=static addr=192.168.1.1 register=PRIMARY
echo 设置完成
pause
exit
:ip6
echo 开启网络共享
cmd /c netsh wlan set hostednetwork mode=allow ssid=AndroidAP key=3043070515
echo 开始启用
cmd /c netsh wlan start hostednetwork
echo 设置完成
pause
exit
if errorlevel 2 goto main
if errorlevel 1 goto end
:test
netsh interface ip set address name = %onlinetype2% source = dhcp
netsh interface ip set dns name = %onlinetype2% source = dhcp
netsh interface ip set wins name = %onlinetype2% source = dhcp
CHOICE /C YN /M "退出请按 Y,返回菜单请按 N。"
if errorlevel 2 goto main
if errorlevel 1 goto end
:end
展开阅读全文