2023-10-22 18:43:54 +08:00
|
|
|
|
rem set mac_addr=11:22:33:aa:bb:cc
|
|
|
|
|
|
|
|
|
|
rem set ipv4_addr=192.168.1.2/24
|
|
|
|
|
rem set ipv4_gateway=192.168.1.1
|
|
|
|
|
rem set ipv4_dns1=192.168.1.1
|
|
|
|
|
rem set ipv4_dns2=192.168.1.2
|
|
|
|
|
|
|
|
|
|
rem set ipv6_addr=2222::2/64
|
|
|
|
|
rem set ipv6_gateway=2222::1
|
|
|
|
|
rem set ipv6_dns1=::1
|
|
|
|
|
rem set ipv6_dns2=::2
|
|
|
|
|
|
|
|
|
|
@echo off
|
2024-03-22 20:05:53 +08:00
|
|
|
|
mode con cp select=437 >nul
|
2023-10-22 18:43:54 +08:00
|
|
|
|
setlocal EnableDelayedExpansion
|
|
|
|
|
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 禁用 IPv6 地址标识符的随机化,防止 IPv6 和后台面板不一致
|
2023-10-22 18:43:54 +08:00
|
|
|
|
netsh interface ipv6 set global randomizeidentifiers=disabled
|
|
|
|
|
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 检查是否定义了 MAC 地址
|
2023-10-28 21:46:38 +08:00
|
|
|
|
if defined mac_addr (
|
|
|
|
|
for /f %%a in ('wmic nic where "MACAddress='%mac_addr%'" get InterfaceIndex ^| findstr [0-9]') do set id=%%a
|
|
|
|
|
if defined id (
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 配置静态 IPv4 地址和网关
|
2023-10-28 21:46:38 +08:00
|
|
|
|
if defined ipv4_addr if defined ipv4_gateway (
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem gwmetric 默认值为 1,自动跃点需设为 0
|
2023-10-28 21:46:38 +08:00
|
|
|
|
netsh interface ipv4 set address !id! static !ipv4_addr! gateway=!ipv4_gateway! gwmetric=0
|
|
|
|
|
)
|
2023-10-22 18:43:54 +08:00
|
|
|
|
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 配置静态 IPv4 DNS 服务器
|
2023-10-28 21:46:38 +08:00
|
|
|
|
for %%i in (1, 2) do (
|
|
|
|
|
if defined ipv4_dns%%i (
|
2024-03-22 00:50:46 +08:00
|
|
|
|
netsh interface ipv4 add | findstr "dnsservers"
|
2024-02-01 01:07:06 +08:00
|
|
|
|
if ErrorLevel 1 (
|
|
|
|
|
rem vista
|
|
|
|
|
netsh interface ipv4 add dnsserver !id! !ipv4_dns%%i! %%i
|
|
|
|
|
) else (
|
|
|
|
|
rem win7
|
|
|
|
|
netsh interface ipv4 add dnsservers !id! !ipv4_dns%%i! %%i no
|
|
|
|
|
)
|
2023-10-28 21:46:38 +08:00
|
|
|
|
)
|
2023-10-22 18:43:54 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 配置 IPv6 地址和网关
|
2023-10-28 21:46:38 +08:00
|
|
|
|
if defined ipv6_addr if defined ipv6_gateway (
|
|
|
|
|
netsh interface ipv6 set address !id! !ipv6_addr!
|
|
|
|
|
netsh interface ipv6 add route prefix=::/0 !id! !ipv6_gateway!
|
|
|
|
|
)
|
2023-10-22 18:43:54 +08:00
|
|
|
|
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 配置 IPv6 DNS 服务器
|
2023-10-28 21:46:38 +08:00
|
|
|
|
for %%i in (1, 2) do (
|
|
|
|
|
if defined ipv6_dns%%i (
|
2024-03-22 00:50:46 +08:00
|
|
|
|
netsh interface ipv6 add | findstr "dnsservers"
|
2024-02-01 01:07:06 +08:00
|
|
|
|
if ErrorLevel 1 (
|
|
|
|
|
rem vista
|
|
|
|
|
netsh interface ipv6 add dnsserver !id! !ipv6_dns%%i! %%i
|
|
|
|
|
) else (
|
|
|
|
|
rem win7
|
|
|
|
|
netsh interface ipv6 add dnsservers !id! !ipv6_dns%%i! %%i no
|
|
|
|
|
)
|
2023-10-28 21:46:38 +08:00
|
|
|
|
)
|
2023-10-22 18:43:54 +08:00
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
2024-01-28 00:00:21 +08:00
|
|
|
|
rem 删除脚本文件
|
2023-10-22 18:43:54 +08:00
|
|
|
|
del "%~f0"
|