@echo off
wmic nic where "NetConnectionStatus='2'" get NetConnectionID|find /c /v "" > %HOMEPATH%\Desktop\1.txt
for /f "delims=" %%a in ('type %HOMEPATH%\Desktop\1.txt') do set count_interf=%%a
if %count_interf% equ 4 (
del %HOMEPATH%\Desktop\1.txt
echo 两个网卡都是活动状态,需要手动配置IP地址
pause
del %0
exit
)
ipconfig|find /i "Pv4 地址 ." > %HOMEPATH%\Desktop\1.txt
for /f "tokens=1* delims=:" %%a in ('type %HOMEPATH%\Desktop\1.txt') do set ip_tmp=%%b
del %HOMEPATH%\Desktop\1.txt
for /f "tokens=1* delims= " %%a in ('echo %ip_tmp%') do set ip=%%a
for /f "tokens=1* delims=." %%a in ('echo %ip%') do set ip_1=%%a
for /f "tokens=1* delims=." %%a in ('echo %ip%') do set ip_2_tmp=%%b
for /f "tokens=1* delims=." %%a in ('echo %ip_2_tmp%') do set ip_2=%%a
for /f "tokens=1* delims=." %%a in ('echo %ip_2_tmp%') do set ip_3_tmp=%%b
for /f "tokens=1* delims=." %%a in ('echo %ip_3_tmp%') do set ip_3=%%a
for /f "tokens=*" %%a in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%a
for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index /value^|find "="') do set %%A
wmic nicconfig where index="%index%" call enablestatic("%ip%"),("255.255.255.0")
wmic nicconfig where index="%index%" call setgateways("%ip_1%.%ip_2%.%ip_3%.1"),(1)
wmic nicconfig where index="%index%" call SetDNSServerSearchOrder("114.114.114.114","218.2.2.2")
wmic nicconfig where index="%index%" call SetTcpipNetbios 2
cls
echo =================
echo IP地址设置成功!
echo =================
set /p pw=请输入系统新密码:
net user administrator %pw%
echo 新密码:"%pw%"设置成功!
pause
del %0