Windows系统自动获取IP地址改成固定IP地址脚本

作者: oldboy 分类: IDC 发布时间: 2023-07-29 15:44
@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

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

标签云