批处理配置IP

2024-12-10  本文已影响0人  自然一夏

@echo off

setlocal enabledelayedexpansion

:: 设置要配置的网络接口名称

set INTERFACE_NAME=本地连接

@echo 自动获取ip地址

netsh interface ip set address name="%INTERFACE_NAME%" source=dhcp

@echo 自动获取DNS服务器

netsh interface ip set dns name="%INTERFACE_NAME%" source=dhcp

:: 设置静态IP配置参数

set STATIC_IP=192.168.100.130

set SUBNET_MASK=255.255.255.0

set GATEWAY_IP=192.168.100.1

set DNS_SERVER1=223.5.5.5

set DNS_SERVER2=202.96.134.133

echo IP:%STATIC_IP%

echo 网关:%GATEWAY_IP%

:: 禁用相关接口

netsh interface set interface "%INTERFACE_NAME%" disabled

:: 启用相关接口

netsh interface set interface "%INTERFACE_NAME%" enabled

:: 设置静态IP地址

netsh interface ip set address name="%INTERFACE_NAME%" static %STATIC_IP% %SUBNET_MASK% gateway=%GATEWAY_IP%

:: 设置DNS服务器

netsh interface ip set dns name="%INTERFACE_NAME%" static %DNS_SERVER1%

netsh interface ip add dns name="%INTERFACE_NAME%" addr=%DNS_SERVER2% index=2

endlocal

exit

上一篇 下一篇

猜你喜欢

热点阅读