【批处理】快速设置IP地址

@echo off

chcp 65001

set prgramname=IP地址快速设置

set producer=高陂中心卫生院网络管理员

set version=V20180717

title %prgramname% %producer% %version%

MODE con: COLS=80 lines=24

color 3a

 

:listnet

 

set netname=

@echo off&setlocal enabledelayedexpansion

set m=0

for /f "skip=3 tokens=4 delims= " %%a in ('netsh interface show interface') do (

set /a m+=1

set name!m!=%%a

)

 

cls

echo               %prgramname%

echo                  %producer%

echo                 %version%

echo.

echo 检测到的网络连接如下:

echo.

echo  1. !name1!

echo.

echo  2. !name2!

echo.

echo  3. !name3!

echo.

echo  4. !name4!

echo.

echo  5. !name5!

echo.

echo  6. !name6!

echo.

echo  7. !name7!

echo.

echo  8. !name8!

echo.

 

CHOICE /C 12345678RVE /N /M "选择要配置的网络请按[1-8],刷新列表按[R],查看IP配置请按[V],退出按[E]:"

 

if errorlevel 11 goto end

if errorlevel 10 goto listip

if errorlevel 9 goto listnet

if errorlevel 8 set netname=!name8!

if errorlevel 7 set netname=!name7!

if errorlevel 6 set netname=!name6!

if errorlevel 5 set netname=!name5!

if errorlevel 4 set netname=!name4!

if errorlevel 3 set netname=!name3!

if errorlevel 2 set netname=!name2!

if errorlevel 1 set netname=!name1!

goto planning

 

:planning

cls

 

echo.

echo 为当前选定 "!netname!" 设置IP地址:

echo.

echo        1.自动获取IP地址

echo.

echo        2.指定IP地址(192.168.2.56)

echo.

echo        3.指定IP地址(192.168.4.249)

echo.

echo        4.指定IP地址(192.168.100.151)

echo.

echo        5.指定IP地址(192.168.123.151)

echo.

echo 注意:请避免IP冲突,不同网络连接的IP地址不能相同!

echo.

choice /C 12345BE /N /M "选择方案请按[1-5],返回请按[B],退出按[E]:"

 

if errorlevel 7 goto end

if errorlevel 6 goto listnet

if errorlevel 5 goto solution5

if errorlevel 4 goto solution4

if errorlevel 3 goto solution3

if errorlevel 2 goto solution2

if errorlevel 1 goto solution1

 

:solution1

 

cls

 

echo.

echo 把 "!netname!" 设置为自动获取IP地址....

echo.

echo  自动获取IP地址....

netsh interface ip set address name = "!netname!" source = dhcp >nul

echo.

echo  自动获取DNS服务器....

netsh interface ip set dns name = "!netname!" source = dhcp >nul

sc config WinHttpAutoProxySvc start= demand >nul

sc stop WinHttpAutoProxySvc >nul

sc config Dhcp start= auto >nul

sc stop Dhcp >nul

sc start WinHttpAutoProxySvc >nul

sc start Dhcp >nul

echo.

 

goto complete

 

:solution2

 

set staddr=192.168.2.56

set stmask=255.255.255.0

set stgway=192.168.2.1

set stdns1=202.96.134.33

set stdns2=202.96.128.86

goto setip

 

:solution3

 

set staddr=192.168.4.249

set stmask=255.255.255.0

set stgway=192.168.4.1

set stdns1=202.96.134.33

set stdns2=202.96.128.86

goto setip

 

:solution4

 

set staddr=192.168.100.151

set stmask=255.255.255.0

set stgway=192.168.0.1

set stdns1=202.96.134.33

set stdns2=202.96.128.86

goto setip

 

:solution5

 

set staddr=192.168.123.151

set stmask=255.255.255.0

set stgway=192.168.123.1

set stdns1=202.96.134.33

set stdns2=202.96.128.86

goto setip

 

:setip

cls

 

echo.

echo 为 "!netname!" 设置IP地址...

echo.

echo   IP地址:%staddr%

echo.

echo   子网掩码:%stmask%

echo.

echo   网关:%stgway%

netsh interface ip set address "!netname!" static %staddr% %stmask% %stgway% 1 >nul

echo.

echo   首选DNS:%stdns1%

netsh interface ip set dns name="!netname!" static %stdns1% primary >nul

echo.

echo   备用DNS:%stdns2%

netsh interface ip add dns name="!netname!" %stdns2% 2 >nul

echo.

choice /t 1 /d y /n >nul

goto complete

 

:complete

cls

 

echo.

ipconfig /flushdns >nul

choice /C BVE /N /M "操作完成,返回请按[B],查看IP配置请按[V],退出请按[E]:"

if errorlevel 3 goto end

if errorlevel 2 goto listip

if errorlevel 1 goto listnet

 

 

:listip

cls

 

choice /t 1 /d y /n >nul

ipconfig

echo.

choice /C BRE /N /M "返回请按[B],刷新请按[R],退出请按[E]:"

if errorlevel 3 goto end

if errorlevel 2 goto listip

if errorlevel 1 goto listnet

 

:end

cls

 

echo.&echo 按任意键退出...

pause>nul

网络相关 2018-08-01 00:11:09 通过 网页 浏览(6)

共有0条评论!

发表评论

更换一道题!