后面发现一个问题,有的服务器netsh interface ip 不生效,可能是服务器做有优化或一些权限设置引起的,改为如下批处理:- @echo off
- set "newip=192.168.16.139"
- set "netmask=255.255.255.0"
- set "gateway=192.168.16.1"
- set "dns1=8.8.8.8"
- set "dns2=8.8.4.4"
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
- echo NetConnectionID="%NetConnectionID%"
- for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
- echo index="%index%"
- wmic nicconfig where index="%index%" call enablestatic("%newip%"),("%netmask%")
- wmic nicconfig where index="%index%" call setgateways("%gateway%"),(1)
- wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("%dns1%","%dns2%")
- wmic nicconfig where index="%index%" call SetTcpipNetbios 2
- exit /b
复制代码
|