2023年12月6日发(作者:)

IP地址、网关、子网掩码快速切换批处理(windowsbat)

在win7下测试通过

::关闭回显

@echo off

title IP快速切换脚本

::

:: -------- 只需要将下面变量替换成需要的地址即可 ---------

set net_interface=本地连接

::办公网段

set ip1=95.16.1.100

set mask1=255.255.0.0

set gateway1=95.16.1.1

::测试网段

set ip2=95.16.2.1

set mask2=255.255.0.0

set gateway2=95.16.2.1

::dns

set dns1=80.32.1.1

set dns2=84.32.2.2

:: -------------------------------------------------------

:CHOICE

color a

cls

echo *****************IP快速切换脚本***********************

echo ----【IP设置功能】---------------【系统功能】-----

echo -----1.修改为办公网段-------------r.重启网卡------

echo -----2.修改为测试网段-------------s.重启计算机----

echo -----3.修改为自动获取-------------x.退出程序------

echo.

echo -----仅对名称为"%net_interface%"的网卡进行设置----

echo *******************By TangTao*************************

:mu

set /p choice= 请输入:

IF NOT "%choice%"=="" SET choice=%choice:~0,1%

if /i "%choice%"=="1" goto ip1

if /i "%choice%"=="2" goto ip2

if /i "%choice%"=="3" goto dhcp

if /i "%choice%"=="r" goto reboot

if /i "%choice%"=="s" goto shutdown

if /i "%choice%"=="x" goto END

echo.

echo.

echo 输入的选择不正确,请重新输入!

echo.

echo.

GOTO CHOICE

::设置办公IP

:ip1

echo.

echo -----------办公IP-----------

echo ip: %ip1%

echo mask: %mask1%

echo gateway1: %gateway1%

echo dns1: %dns1%

echo dns2: %dns2%

::同时设置ip、mask、gateway,不要分别设置

cmd /c netsh interface ip set address "%net_interface%" source=static addr=%ip1% mask=%mask1% gateway=%gateway1%

::设置dns

cmd /c netsh interface ip set dnsservers "%net_interface%" static %dns1%

cmd /c netsh interface ip add dnsservers "%net_interface%" %dns2% index=2

ipconfig /flushdns

echo 设置完成

echo 设置完成

pause | echo 按任意键返回选择菜单

GOTO CHOICE

::设置测试IP

:ip2

echo.

echo -----------测试IP-----------

echo ip: %ip2%

echo mask: %mask2%

echo gateway1: %gateway2%

echo dns1: %dns1%

echo dns2: %dns2%

::同时设置ip、mask、gateway,不要分别设置

cmd /c netsh interface ip set address "%net_interface%" source=static addr=%ip2% mask=%mask1% gateway=%gateway2%

::设置dns

cmd /c netsh interface ip set dns "%net_interface%" static %dns1%

cmd /c netsh interface ip add dns "%net_interface%" %dns2% index=2

ipconfig /flushdns

echo 设置完成

pause | echo 按任意键返回选择菜单

GOTO CHOICE

::设置dhcp

:dhcp

echo.

echo ---设置ip/dns为自动获取---

cmd /c netsh interface ip set address name="%net_interface%" source=dhcp

cmd /c netsh interface ip set dns "%net_interface%" source=dhcp

echo 设置完成

pause | echo 按任意键返回选择菜单

GOTO CHOICE

:reboot

::设置reboot

cmd /c netsh interface set interface "%net_interface%" disabled

cmd /c netsh interface set interface "%net_interface%" enable

echo 重启网卡完成

pause | echo 按任意键返回选择菜单

GOTO CHOICE

:shutdown

shutdown /r /f /t 30

:END

Exit