上面的这种修改方法有些地方不是很严密,我感觉。 特提供我写的脚本。
@Echo off
Title Please waitting. update computer information.
set flName=c:\windows\ip.txt
set netMask=255.255.255.0
set Gateway=192.168.1.254
set Metric=1
set DNS1=61.177.7.1
set DNS2=221.228.255.1
set DNS3=218.2.135.1
IF EXIST D:\ %windir%\system32\CSCRIPT %windir%\system32\PAGEFILECONFIG.vbs /create /I 768 /M 1536 /VO d: >nul
if EXIST E:\ %windir%\system32\CSCRIPT %windir%\system32\PAGEFILECONFIG.vbs /create /I 512 /M 768 /VO E: >nul
IF EXIST C:\ %windir%\system32\CSCRIPT %windir%\system32\PAGEFILECONFIG.vbs /change /I 512 /M 768 /VO C: >nul
REM GET ComputerName,AdapName,Phyaddr
for /f "tokens=2 delims=:" %%a in ('ipconfig /all^|find "Host Name"') do set pcName=%%a
for /f "tokens=3 delims= " %%a in ('ipconfig /all^|find "Ethernet adapter"') do set AdapName=%%a
for /f "tokens=2 delims=:" %%a in ('ipconfig /all^|find "Physical Address"') do set PhyAddr=%%a
set pcName=%pcName:~1%
set AdapName=%AdapName:~0,-2%
set PhyAddr=%PhyAddr:~1%
set mac1=%PhyAddr:~0,2%
set mac2=%PhyAddr:~3,2%
set mac3=%PhyAddr:~6,2%
set mac4=%PhyAddr:~9,2%
set mac5=%PhyAddr:~12,2%
set mac6=%PhyAddr:~15,2%
set PhyAddr=%mac1%%mac2%%mac3%%mac4%%mac5%%mac6%
set wmicMac=%mac1%:%mac2%:%mac3%:%mac4%:%mac5%:%mac6%
:Echo %pcName% %AdapName% %PhyAddr%
REM Find ip-Mac addr @ file.
for /f "skip=2 tokens=1,2,3,4" %%a in ('find "%PhyAddr%" "%flName%"') do call :findok %%b %%a %%c
goto end
REM Change Computer name
REM
:setok
@Echo This computer's mac is: %1 ipaddress is: %2 name is: %3
@Echo Please waitting...
@Echo Now,update computer name
WMIC computersystem where Name="%pcName%" call Rename Name="%3" >nul
@Echo Modify ip address
WMIC NICCONFIG WHERE MACAddress="%wmicMac%" call EnableStatic("%2"),("%netMask%") >nul
WMIC NICCONFIG WHERE MACAddress="%wmicMac%" call SetGateways("%Gateway%") >nul
@Echo Modify DNS
WMIC NICCONFIG WHERE MACAddress="%wmicMac%" call SetDNSServerSearchOrder("%DNS1%", "%DNS2%", "%DNS3%") >nul
:end
@Echo All Done!
IP.txt 基本结构:
192.168.1.1 001A928EFC1E PC001 WORKGROUP
192.168.1.2 001A9235D870 PC002 WORKGROUP
192.168.1.3 001A928EF04E PC003 WORKGROUP
192.168.1.4 001A9235B64D PC004 WORKGROUP
192.168.1.5 001A928EF37A PC005 WORKGROUP
192.168.1.6 001A928EF12E PC006 WORKGROUP
192.168.1.7 001A928EE291 PC007 WORKGROUP
192.168.1.8 001A928EE318 PC008 WORKGROUP
192.168.1.9 001A928EF187 PC009 WORKGROUP
192.168.1.10 001A928EF44A PC010 WORKGROUP