之前用一个别人提供的批处理批量改IP,在XP环境下,现在想换成WIN7,该批处理没用了。
代码是这样的:- @color c
- @cls
- @echo [ComputersMAC] [Name] [ip] >name.xmz
- @echo 44-87-FC-64-58-8D A7 17 >>name.xmz
- @echo 00-00-00-00-00-00 A1 11 >>name.xmz
- @echo 44-87-FC-64-5B-8D A5 15 >>name.xmz
- @echo 44-87-FC-64-5B-27 A2 12 >>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"="%name%" >>Cname.reg
-
- @echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>Cname.reg
-
- @echo "NV Hostname"="%name%" >>Cname.reg
-
- @echo "Hostname"="%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.11.%ip% mask=255.255.255.0 gateway=192.168.11.2 gwmetric=0
- netsh interface ip set dns name="本地连接" source=static addr=202.96.128.166 >nul 2>nul
- netsh interface ip add dns name="本地连接" addr=202.96.128.86 index=2 >nul 2>nul
-
-
-
- del /q *.xmz
- del /q *.reg
复制代码 XP和WIN7下的Ipconfig的区别:除了win7的变成中文外,还出现了三个“物理地址”这个关键字眼。但代码实在不会改,哪位大侠帮个忙。谢谢!
后来又找到一个好似更简便的代码,不知有没用。代码如下:- @echo off
- color 0a
- :::--------------------------------------------------------------------------
- ::: ##@请修改机房中所有计算机名、MAC地址、ip地址加入到下面行,不够另起一行@##
- @cls :::清屏
- @echo [ComputerName] [MacAddress] [IPAddress] >config.cfg
- @echo a1 94-DE-80-2E-E5-DD 192.168.1.21 >>config.cfg
- @echo a3 94-DE-80-2E-E5-D4 192.168.1.23 >>config.cfg
-
- :::--------------------------------------------------------------------------
-
-
- :::::::添加你自己的机器配置
- @echo 正在获取机器的TCP/IP 配置
- ipconfig /all >ipconfig.txt
- :::分离出机器的物理地址,并保存到 ( phyaddr.txt) 文件中
- find "物理地址" ipconfig.txt >phyaddr.txt
- ::::从(c:\phyaddr.txt)文件中取得物理地址字符串,并赋给变量"MacAddress"
- for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set strMac=%%M
- :::显示物理地址字符串
- @echo 显示物理地址字符串: %strMac%
- ::::以变量"strMac"为关键字搜索(Config.cfg)中相同的字符串行,并保存到(ComputerCfg.txt)
- find "%strMac%" Config.cfg >ComputerCfg.txt
- ::::显示机器名. (从"ComputerCfg.txt"中分离出 机器名字段,并赋给变量"ComputerName")
- for /f "skip=2 tokens=1" %%N in (ComputerCfg.txt) do set ComputerName=%%N
- @echo 显示机器名 %ComputerName%
- ::::显示IP地址. (从"ComputerCfg.txt"中分离出 IP地址字段,并赋给变量"IPAddress")
- for /f "skip=2 tokens=3" %%I in (ComputerCfg.txt) do set IPAddress=%%I
- @echo 显示IP地址: %IPAddress%
- ::::显示网卡MAC地址.(从"ComputerCfg.txt"中分离出 MAC地址字段,并赋给变量"MacAddress")
- for /f "skip=2 tokens=2" %%M in (ComputerCfg.txt) do set MacAddress=%%M
- @echo 显示网卡MAC地址: %MacAddress%
- ::::创建注册表文件
- @echo Windows Registry Editor Version 5.00 >ComputerName.reg
- @echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName] >>ComputerName.reg
- ::::用变量"%ComputerName%"去替换实际的机器名
- @echo "ComputerName"="%ComputerName%" >>ComputerName.reg
- @echo [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters] >>ComputerName.reg
- ::::用变量"%ComputerName%"去替换实际的机器名
- @echo "NV Hostname"="%ComputerName%" >>ComputerName.reg
- @echo "Hostname"="%ComputerName%" >>ComputerName.reg
- ::::导入注册表文件。用的时候把" :: " 去掉
- regedit /s ComputerName.reg
-
-
- ::::修改IP 地址。用变量"%IPAddress%" 去替换实际的IP 地址
- :::--------------------------------------------------------------------------
- ::::####@请确保下一行命令中的“网络连接”的名称和电脑上的一致,如"无线网络连接","本地连接","本地连接1"等等。。。@##
- netsh interface ip set address "本地连接" source=static addr=%IPAddress% mask=255.255.255.0 gateway=192.168.1.1 gwmetric=1
- ::::####@请根据实际情况更改首选DNS,去掉下行命令前的::::就可执行@##
- netsh interface ip set dns "本地连接" static 202.96.134.133
- ::::####@请根据实际情况更改第二DNS,去掉下行命令前的::::就可执行@##
- netsh interface ip add dns "本地连接" 202.96.128.166 2
- :::--------------------------------------------------------------------------
复制代码
|