一、批处理代码
@color c
@cls
@echo [ComputersMAC] [Name] [ip] >name.xmz
@echo XX-XX-XX-XX-XX-XX A1 01 >>name.xmz
@echo XX-XX-XX-XX-XX-XX A2 02 >>name.xmz
@echo XX-XX-XX-XX-XX-XX A3 03 >>name.xmz
@cls
ipconfig /all >ipconfig.xmz
find "Physical Address" ipconfig.xmz >mac.xmz
for /f "skip=1 tokens=12" %%C in (mac.xmz) do set mac=%%C
find "%mac%" name.xmz >key.xmz
for /f "skip=1 tokens=2" %%C in (key.xmz) do set name=%%C
for /f "skip=1 tokens=3" %%C in (key.xmz) do set ip=%%C
@echo %name%
@echo %ip%
@echo Windows Registry Editor Version 5.00 >Cname.reg
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] >>Cname.reg
@echo "ComputerName"="cjb-%name%" >>Cname.reg
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>Cname.reg
@echo "NV Hostname"="cjb-%name%" >>Cname.reg
@echo "Hostname"="cjb-%name%" >>Cname.reg
@echo Windows Registry Editor Version 5.00 >insn.reg
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>insn.reg
@echo "VirtualNetworkNumber"=dword:00000%name% >>insn.reg
@echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NwlnkIpx\Parameters] >>insn.reg
@echo "VirtualNetworkNumber"=dword:00000%name% >>insn.reg
regedit /s Cname.reg
regedit /s insn.reg
netsh interface ip set address name="本地连接" source=static addr=192.168.0.%ip% mask=255.255.255.0 gateway=192.168.0.1 gwmetric=0
del /q *.xmz
del /q *.reg
二、代码说明
以上代码所出现的XX-XX-XX-XX-XX-XX指的就是机器MAC地址,想让每台计算机都自动改,事先得去收集机房中所有机器的MAC地址,并逐一添加进去。
XX-XX-XX-XX-XX-XX后面是:你要设置的计算机名和要设置其IP的最后一段地址。