menu Chancel's Blog
rss_feed lightbulb_outline

Windows切换IP脚本

类型:Windows
创建时间:2021-06-16 10:36:24
更新时间:2021-06-16 10:36:24
类型:Windows
更新时间:2021-06-16 10:36:24

IP切换脚本,修改其中的2个IP配置即可

ip切换脚本下载地址 - Chancel's Cloudreve

::关闭回显
@echo off
title 快速切换IP设置

::设置背景颜色
setlocal EnableDelayedExpansion&color 3e & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
:runas

:: -------- 更改以下2个IP配置以及网卡名称(网卡名称如本地连接) ---------
set net_interface=本地连接 3
::公司网段
set name1=公司网段
set ip1=192.168.4.16
set mask1=255.255.240.0
set gateway1=192.168.3.1
set dns1_1=223.5.5.5
set dns1_2=192.168.3.1
::科学网段
set name2=科学网段
set ip2=192.168.4.16
set mask2=255.255.240.0
set gateway2=192.168.4.93
set dns2_1=192.168.4.93
set dns2_2=223.5.5.5
:: -------------------------------------------------------

:CHOICE
cls
echo.
echo                        IP快速切换脚本
echo.
echo --------------------------------------------------------------------------------                                                        
echo             1. 修改为%name1%%ip1%/%gateway1%echo             2. 修改为%name2%%ip2%/%gateway2%echo             3. 修改为自动获取
echo             4. 重启网卡
echo.
echo --------------------------------------------------------------------------------

: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%"=="4" goto reboot
echo.
echo.
echo 输入的选择不正确,请重新输入!
echo.
echo.
GOTO CHOICE

::设置IP-1
:ip1
echo.
echo  -----------%name1%-----------
echo       ip:  %ip1%
echo     mask:  %mask1%
echo gateway1:  %gateway1%
echo     dns1:  %dns1_1%
echo     dns2:  %dns1_2%
::设置IP/网关/子网掩码
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_1% validate=no
cmd /c netsh interface ip add dnsservers "%net_interface%" %dns1_2% index=2 validate=no
ipconfig /flushdns
echo 设置完成
pause | echo 按任意健退出程序
exit /b
:END

::设置IP-2
:ip2
echo.
echo  -----------%name2%-----------
echo       ip:  %ip2%
echo     mask:  %mask2%
echo gateway1:  %gateway2%
echo     dns1:  %dns2_1%
echo     dns2:  %dns2_2%
::设置IP/网关/子网掩码
cmd /c netsh interface ip set address "%net_interface%" source=static addr=%ip2% mask=%mask1% gateway=%gateway2%
::设置DNS
cmd /c netsh interface ip set dnsservers "%net_interface%" static %dns2_1% validate=no
cmd /c netsh interface ip add dnsservers "%net_interface%" %dns2_2% index=2 validate=no
ipconfig /flushdns
echo 设置完成
pause | echo 按任意健退出程序
exit /b
:END

::设置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 按任意健退出程序
exit /b
:END

:reboot
::重启网卡
cmd /c netsh interface set interface "%net_interface%" disabled
cmd /c netsh interface set interface "%net_interface%" enable
echo 重启网卡完成
pause | echo 按任意健退出程序
exit /b
:END

[[replyMessage== null?"发表评论":"@" + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageList.data.items.length]])

[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[messageItem.m_environ.browser]] [[messageItem.m_environ.os]] [[messageItem.m_environ.device]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[subMessage.m_environ.browser]] [[subMessage.m_environ.os]] [[subMessage.m_environ.device]]