复制代码
- @echo off
- mode con: cols=58 lines=50
- color 6f
- title [IP设置程序] by xieqingx 20100313
- cls
- @echo.
- @echo 正在获取信息....
- setlocal EnableDelayedExpansion
- cd.>%temp%\IPinfo123.txt
- for /f "delims=," %%i in ('ipconfig /all') do (@echo. %%i>>%temp%\IPinfo123.txt
- )
- echo.
- for /f "tokens=3" %%a in ('find /I "Ethernet adapter" %temp%\IPinfo123.txt') do (
- set linkN=%%a
- set linkN=!linkN::=!
- @echo 适配器名称是 !linkN!
- )
- for /f "tokens=12" %%a in ('find /I "Physical Address" %temp%\IPinfo123.txt') do ( @echo MAC地址是 %%a&&set mac=%%a)
- @echo off
- setlocal EnableDelayedExpansion
- for /f "tokens=14" %%a in ('find /i "Dhcp Enabled" %temp%\IPinfo123.txt') do (
- set "dhcp=%%a"
- set "dhcp=!dhcp:~0,2!"
- if "!dhcp!" equ "No" (
- set "dhcp=固定IP设置"
- set sta=自动获取IP
- set mark=dhcp
- ) else (
- set "dhcp=自动获取IP"
- set sta=固定IP设置
- set mark=nodhcp
- )
- )
- for /f "tokens=15" %%a in ('find /I "ip address" %temp%\IPinfo123.txt') do @echo IP是 %%a&&set ip=%%a
- for /f "tokens=15" %%a in ('find /I "Subnet Mask" %temp%\IPinfo123.txt') do @echo 子网掩码是 %%a&&set subm=%%a
- for /f "tokens=13" %%a in ('find /I "Default Gateway" %temp%\IPinfo123.txt') do @echo 网关是 %%a&&set getway=%%a
- for /f "tokens=1,16" %%a in ('findstr /n /c:"DNS Servers" %temp%\IPinfo123.txt') do (
- set num=%%a
- set num=!num::=!
- @echo DNS服务器是 %%b&&set dns1=%%b
- )
- if not defined num ( echo.&&set "dns1mark=1"&&echo 没有主DNS服务器&&goto :end) else (
- for /F %%a in ('findstr ".*" %temp%\IPinfo123.txt') do (set dns2=%%a
- )
- if /i !dns2!==dns (goto :end ) else (
- for /f %%a in ('more +%num% %temp%\IPinfo123.txt') do (
- set/a n+=1
- if !n!==1 ( set dns2=%%a
- if /i !dns2!==lease (goto :end) else (
- @echo DNS备选服务器是 !dns2!)
- )
- )
- goto :next))
- :end
- echo.
- set dnsmark=2
- @echo 没有备选DNS服务器
- :next
- echo.&echo.
- echo 当前为!dhcp!,请问要转换!sta!方式吗?
- echo.
- echo.
- echo 1、自动转换
- echo.
- echo 2、不转换
- echo.
- echo 3、手动设IP
- echo.
- echo X、退出
- echo.
- set choice=
- set /p choice= 请输入指定功能代码(1/2/3/X):
- echo.
- if not defined choice cls&&goto next
- if /i "%choice:~0,1%"=="X" exit
- set "choice=%choice:~0,1%"
- if "%choice%"=="1" goto 1
- if "%choice%"=="2" goto 2
- if "%choice%"=="3" goto 3
- :1
- @echo 请稍候正在设置
- @echo.
- if "!mark!"=="dhcp" (
- @echo 正在设置ip自动获取.....
- netsh interface ip set address name="%linkN%" source=dhcp>nul
- @echo 正在设置Dns自动获取.....
- netsh interface ip set dns name="%linkN%" source=dhcp register=PRIMARY>nul
- @echo 正在设置Wins自动获取.....
- netsh interface ip set wins name="%linkN%" source=dhcp>nul
- ) else (
- @echo 正在设置 ip、submask、getway
- netsh interface ip set address name="%linkN%" source=static addr=%IP% mask=%subm% gateway=%getway% gwmetric=0 >nul
- if /i "%dns1mark%"=="1" ( @echo 无主要DNS,跳过设置) else (
- @echo 正在设置 主DNS
- netsh interface ip set dns name="%linkN%" source=static addr=%dns1% register=PRIMARY>nul
- )
- if /i "%dnsmark%"=="2" ( @echo 无备用DNS,跳过设置) else (
- @echo 正在设置 备用DNS
- netsh interface ip add dns name="%linkN%" addr=%dns2%>nul
- )
- @echo 正在设置 Wins
- netsh interface ip set wins name="%linkN%" source=static addr=none>nul
- )
- goto :2
- :3
- set /p choice2= 确定要手动设置吗?(y/n):
- echo.
- if not defined choice2 goto 3
- set "choice2=%choice2:~0,1%"
- if "%choice2%"=="n" (goto 2) else (if "%choice2%"=="y" ( goto next2) else (echo 请输入正确选项&&goto :3))
- :next2
- set slection1=
- set/p slection1= 请输入IP地址:
- set slection5=
- set/p slection5= 请输入子网掩码地址:
- set slection2=
- set/p slection2= 请输入网关地址:
- set slection3=
- set/p slection3= 请输入主dns地址:
- set slection4=
- set/p slection4= 请输入备选dns地址:
- @echo 正在设置.....
- netsh interface ip set address name="%linkN%" source=static addr=%slection1% mask=%slection5% gateway=%slection2% gwmetric=0
- netsh interface ip set dns name="%linkN%" source=static addr=%slection3% register=PRIMARY
- netsh interface ip add dns name="%linkN%" addr=%slection4%
- netsh interface ip set wins name="%linkN%" source=static addr=none
- :2
- @echo.
- @echo 完成设置!
- @echo.
- @echo 按任意键退出本程序
- pause>nul
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |