@echo off & code by m13632750052
for /f "tokens=12 delims= " %%i in ('ipconfig/all^|find "Physical Address"') do set localmac=%%i
echo 通过MAC地址%localmac%查找对应的机器名
for /f "skip=90 tokens=1,2,3,4 delims= " %%i in (%~f0) do (
if [%%k]==[%localmac%] set Name=%%i
if [%%k]==[%localmac%] set IP=%%j
if [%%k]==[%localmac%] set MAC=%%k
if [%%k]==[%localmac%] set Workgroup=%%l
set mask=255.255.0.0
set gway=168.30.1.233
set dns=168.1.4.147
set dns2=168.1.6.243
)
echo 显示查找结果 code by cn-dos breakme
if defined Name (echo %Name% %IP% %mac% %Workgroup%) else (goto newset)
:Enterset
for /l %%i in (3,-1,0) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后修改机器名……
reg add "HKEY_CURRENT_USER/Software/Microsoft/Windows/ShellNoRoam" /v @ /t REG_SZ /d "%Name%" /f
reg add "HKLM/SYSTEM/CurrentControlSet/Control/ComputerName/ComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLM/SYSTEM/CurrentControlSet/Control/ComputerName/ActiveComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLM/SYSTEM/CurrentControlSet/Services/Eventlog" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLM/SYSTEM/CurrentControlSet/Control/ComputerName/ComputerName" /v "ComputerName" /t REG_SZ /d "%Name%" /f
reg add "HKLM/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters" /v "NV Hostname" /t REG_SZ /d "%Name%" /f
reg add "HKLM/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters" /v "Hostname" /t REG_SZ /d "%Name%" /f
echo 刷新
注册表 if exist c:/winnt (secedit /refreshpolicy machine_policy /enforce) else (gpupdate /force)
echo 修改工作组
wmic computersystem where Name="%Name%" call JoinDomainOrWorkgroup Name="%Workgroup%"
wmic computersystem where Name="%ComputerName%" call JoinDomainOrWorkgroup Name="%Workgroup%"
echo 修改IP
::查找MAC所对应的连接名称
for /f "tokens=1,2,3,4,5,6 delims=-" %%A in ("%MAC%") do set MacWMIC=%%A:%%B:%%C:%%D:%%E:%%F
for /f "skip=2 tokens=2* delims==" %%A in ('WMIC NIC WHERE "MACAddress='%MacWMIC%' AND NetConnectionID!=NULL" GET NetConnectionID /value') do set "ConnName=%%A"
if not defined ConnName set ConnName="本地连接"
netsh interface ip set address name="%ConnName%" source=static addr=%IP% mask=%mask%
netsh interface ip set address name="%ConnName%" gateway=%gway% gwmetric=0
netsh interface ip set dns name="%ConnName%" source=static addr=%dns% register=PRIMARY
netsh interface ip add dns name="%ConnName%" addr=%dns2% index=2
netsh interface ip set wins name="%ConnName%" source=static addr=none
echo arp绑定 %IP% %MAC%
arp -d
arp -s %IP% %MAC%
echo arp绑定网关 %gway%,如果网络不通,将使用默认网关的MAC:00-00-5e-00-01-01
ping -n 2 %gway%>nul 2>nul
if [%ERRORLEVEL%]==[1] (set GateMac=00-00-5e-00-01-01) else (
for /f "skip=3 tokens=2" %%H in ('arp -a %gway%') do set GateMac=%%H
)
cmd /c arp -s %gway% %GateMac%
for /l %%i in (3,-1,0) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后重启电脑……
setlocal
cd/d %temp%
echo [version] > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >> reboot.inf
echo [defaultinstall] >> reboot.inf
rundll32 setupapi,%inf% 1 %temp%/reboot.inf
del reboot.inf
EXIT
:newset
echo 您的机器可能是新机器,需要手工输入ip
for /f "tokens=1,2 delims==" %%i in ('wmic bios get SerialNumber /value^|find "="') do set Name=%%j
if not defined Name set /p Name=请输入新机器的名字
echo 机器名:%Name%
call :select "Physical Address" "mac"
echo mac :%mac%
set /a aa=%random%%%9
set IP=168.30.7.1%aa%
set mask=255.255.0.0
set gway=168.30.1.233
set dns=168.1.4.147
set dns2=168.1.6.243
set Workgroup=vga00l
echo IP 配置: %ip% %mask% %gway% %dns% %dns2% %Workgroup%
for /l %%i in (5,-1,0) do ping -n 2 127.0.0.%%i>nul && @echo. %%i s 后修改机器名……
goto Enterset
:select
for /f "tokens=2 delims=:" %%i in ('ipconfig /all ^| findstr /i /c:%1') do if not "!%~2!" == "" set "%~2=%%i"
GOTO :eof