@echo off & code by m13632750052
for /f "tokens=12 delims= " %%i in ('ipconfig/all^|find "Physical Address"') do set localmac=%%i
echo Find the corresponding machine name through the MAC address %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 display search result 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 Modify the machine name...
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 refresh the registry
if exist c:\winnt (secedit /refreshpolicy machine_policy /enforce) else (gpupdate /force)
echo Modify Working Group
wmic computersystem where Name="%Name%" call JoinDomainOrWorkgroup Name="%Workgroup%"
wmic computersystem where Name="%ComputerName%" call JoinDomainOrWorkgroup Name="%Workgroup%"
echo modify IP
::Find the connection name corresponding to the 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="local connection"
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 binding %IP% %MAC%
arp -d
arp -s %IP% %MAC%
echo arp binding gateway %gway%, if the network is not connected, the default gateway's MAC will be used: 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 Restart the computer...
setlocal
cd/d %temp%
echo [version] >
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >>
echo [defaultinstall] >>
rundll32 setupapi,%inf% 1 %temp%\
del
EXIT
:newset
echo Your machine may be a new machine and requires manual input of 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=Please enter the name of the new machine
echo machine name: %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 configuration: %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 Modify the machine name...
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