echo off set OLD_FIRST_OCTET 20 Generate new computername for tokens d

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
@echo off
set OLD_FIRST_OCTET="20"
:: Generate new computername
for /f "tokens=1,2,3 delims=- " %%a in ("%computername%") do set MV=%%a&set AREA=%%b&set SUF=%%c
SET computernameMAP=108-18;24-21;134-23;184-25;54-27;74-29;214-19;100-17;109-17-10X
CALL SET AREA=%%computernameMAP:*%AREA%-=%%
SET AREA=%AREA:;=&rem.%
SET PCNAME=%MV%-%AREA%-%SUF%
ECHO."%computername% to %PCNAME%"
::---- Change computername
::REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %PCNAME% /f
::REG ADD HKLM\SYSTEM\ControlSet001\Services\Eventlog /v ComputerName /t REG_SZ /d %PCNAME% /f
::REG ADD HKLM\SYSTEM\ControlSet001\Services\Tcpip\Parameters /v Hostname /t REG_SZ /d %PCNAME% /f
::REG ADD HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName /v ComputerName /t REG_SZ /d %PCNAME% /f
::REG ADD HKLM\SYSTEM\CurrentControlSet\Services\Eventlog /v ComputerName /t REG_SZ /d %PCNAME% /f
::REG ADD HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v Hostname /t REG_SZ /d %PCNAME% /f
::REG ADD HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v "NV Hostname" /d %PCNAME% /f
:: ---- Get IP address
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| find "IP" ^| find %OLD_FIRST_OCTET%') do set IP=%%a
set IP=%IP:~1%
:: Split IP into octets
for /f "tokens=2,3,4 delims=." %%a in ("%IP%") do set O2=%%a&set O3=%%b&set O4=%%c
echo %IP%
SET secondOctetMAP=108-18;24-21;134-23;184-25;54-27;74-29;214-19;100-17;109-17
CALL SET O2=%%secondOctetMAP:*%O2%-=%%
SET O2=%O2:;=&rem.%
netsh interface ip set address LAN1 static 172.%O2%.4.%O4% 255.255.255.0 172.%O2%.4.254 1