这样试- @echo off
- set nic=本地连接
- for /f "skip=1" %%i in ('wmic Nic where "NetConnectionID='%nic%'" get MACAddress^,NetConnectionID 2^>^&1') do (
- for %%a in (%%i) do set "mac=%%a"
- )
- if not defined mac (
- set "nic="
- for /f "skip=1tokens=*" %%i in ('wmic Nic get MACAddress^,NetConnectionID') do (
- for /f "tokens=1*" %%a in ("%%i") do (
- if "%%~nxb" neq "" (
- set mac=%%a&set "nic=%%~nxb"
- ) else if not defined mac set mac=%%a
- )
- )
- )
- set ip=
- if not defined nic set nic=本地连接
- if defined mac for /f "tokens=2" %%a in ('findstr /ibc:"%mac%" 1.txt') do set "ip=%%a"
- if not defined ip echo,没有ip可匹配&pause&exit
- set mask=255.255.255.0
- set gateway=192.168.0.1
- set dns=21.156.240.1
- netsh interface ip set address "%nic%" static %ip% %Mask% %gateway% 1 >nul 2>nul
- netsh interface ip set dns "%nic%" static %dns% >nul 2>nul
- pause
复制代码
|