以下是一个示例批处理程序,可以用于切换本地的五个不同网段的IP地址:

@echo off REM IP地址列表 set ip1=192.168.0.10 set ip2=172.16.1.20 set ip3=10.0.0.30 set ip4=192.168.1.40 set ip5=172.17.2.50

REM 子网掩码和DNS set subnet=255.255.255.0 set dns=8.8.8.8

REM 网关列表 set gateway1=192.168.0.1 set gateway2=172.16.1.1 set gateway3=10.0.0.1 set gateway4=192.168.1.1 set gateway5=172.17.2.1

REM 选择IP地址 echo 请选择要使用的IP地址: echo 1. %ip1% echo 2. %ip2% echo 3. %ip3% echo 4. %ip4% echo 5. %ip5% set /p ip=输入数字选择IP地址:

REM 设置IP地址和网关 if %ip% equ 1 ( netsh interface ip set address '本地连接' static %ip1% %subnet% %gateway1% 1 ) if %ip% equ 2 ( netsh interface ip set address '本地连接' static %ip2% %subnet% %gateway2% 1 ) if %ip% equ 3 ( netsh interface ip set address '本地连接' static %ip3% %subnet% %gateway3% 1 ) if %ip% equ 4 ( netsh interface ip set address '本地连接' static %ip4% %subnet% %gateway4% 1 ) if %ip% equ 5 ( netsh interface ip set address '本地连接' static %ip5% %subnet% %gateway5% 1 )

REM 设置DNS netsh interface ip set dns '本地连接' static %dns%

REM 显示设置好的IP地址 ipconfig

pause

REM 恢复DHCP netsh interface ip set address '本地连接' dhcp

echo DHCP已恢复。

pause

exit

注意:在使用此批处理程序之前,请确保将'本地连接'替换为您计算机上的实际网络连接名称。另外,请注意,此脚本会更改您的网络设置,请小心操作。

批处理程序:轻松切换不同网段IP地址 (含DNS和网关设置)

原文地址: https://www.cveoy.top/t/topic/nsSQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录