- @echo off
- setlocal enabledelayedexpansion
-
- rem 获取所有本地连接信息
- for /f "tokens=2 delims=:" %%i in ('ipconfig ^| findstr "Ethernet adapter"') do (
- set "adapter=%%i"
- set "adapter=!adapter:~1!"
- echo !adapter! | findstr /r "^Ethernet adapter .*$" >nul || (
- set "ipv4="
- for /f "tokens=2 delims=:" %%j in ('ipconfig /all ^| findstr /c:"!adapter!" /c:"IPv4 Address"') do (
- set "val=%%j"
- set "val=!val:~1!"
- set "val=!val: =!"
- if not defined ipv4 (
- echo !val! | findstr /r "^172\.16\.100\..*$" >nul && set "ipv4=!val:~-1!"
- )
- )
- if defined ipv4 (
- set "ipv6=240e:46:e706:4001:!ipv4!"
- netsh interface ipv6 set address "!adapter!" "!ipv6!" store=persistent >nul
- echo !adapter!: !ipv6!
- )
- )
- )
复制代码
|