[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] [已解决]批处理如何根据MAC地址自动改IP,计算机名?

本帖最后由 滴血雄鹰 于 2019-3-19 12:57 编辑

下面批处理可以在XP下根据MAC地址自动改IP,计算机名,但在WIN7下用不了,请高手修改下?计算机名要不重启就生效的。
  1. @echo off
  2. echo 正在配置IP地址、DNS请稍候……
  3. set MASK=255.255.255.0
  4. set GATEWAY=192.168.103.254
  5. set DNS1=202.96.128.143
  6. set DNS2=202.96.128.68
  7. set WINS=192.168.103.254
  8. for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "Physical Address"') do set mac=%%i
  9. for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "Ethernet adapter"')  do set Ethernet=%%k
  10. for /f "tokens=1,2" %%i in ('more /e +21 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"&set "IP=%%j"
  11. for /f "tokens=4" %%j in ('more /e +21 %0 ^|find /i "%mac:~,-1%"') do set "p=%%j"
  12. reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
  13. reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
  14. reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
  15. reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
  16. reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
  17. netsh interface ip set address "%Ethernet:~,-2%" static %IP% %Mask% %GATEWAY% 1 >nul 2>nul
  18. netsh interface ip set dns "%Ethernet:~,-2%" static %DNS1% register=PRIMARY >nul 2>nul
  19. netsh interface ip add dns "%Ethernet:~,-2%"  %DNS2% index=2 >nul 2>nul
  20. netsh interface ip set wins "%Ethernet:~,-2%" static %WINS%  >nul 2>nul
  21. exit
  22. A01 192.168.103.101 10-60-4b-77-fe-a0 北三楼A01
  23. A02 192.168.103.102 10-60-4b-8b-50-be 北三楼A02
  24. A03 192.168.103.103 10-60-4b-88-61-7f 北三楼A03
  25. A04 192.168.103.104 10-60-4b-88-70-a6 北三楼A04
  26. A05 192.168.103.105 10-60-4B-89-46-CE 北三楼A05
  27. A06 192.168.103.106 10-60-4b-8b-51-3f 北三楼A06
  28. A07 192.168.103.107 10-60-4b-8b-53-cd 北三楼A07
  29. A08 192.168.103.108 10-60-4b-8b-51-38 北三楼A08
  30. A09 192.168.103.109 10-60-4b-77-e5-c4 北三楼A09
  31. A10 192.168.103.110 10-60-4b-77-ea-c2 北三楼A10
  32. B01 192.168.103.111 10-60-4b-77-e7-e6 北三楼B01
  33. B02 192.168.103.112 10-60-4b-77-fe-80 北三楼B02
  34. B03 192.168.103.113 10-60-4b-88-5e-cc 北三楼B03
  35. B04 192.168.103.114 10-60-4b-77-ea-a9 北三楼B04
  36. B05 192.168.103.115 10-60-4b-77-fe-9e 北三楼B05
  37. B06 192.168.103.116 10-60-4b-77-e7-eb 北三楼B06
  38. B07 192.168.103.117 10-60-4b-88-70-a1 北三楼B07
  39. B08 192.168.103.118 10-60-4b-8b-50-99 北三楼B08
  40. B09 192.168.103.119 10-60-4b-86-2f-d2 北三楼B09
  41. B10 192.168.103.120 10-60-4b-77-fe-f4 北三楼B10
复制代码
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

回复 2# jiavip


改了还是没有用?是不是有多个“物理地址”,冲突了?IPCONFIG /ALL的内容见附件1.TXT

链接: https://pan.baidu.com/s/1ZFZWMXj7H9ZeJEIXC9oYaw 提取码: ee5v


@echo off
echo 正在配置IP地址、DNS请稍候……
set MASK=255.255.255.0
set GATEWAY=192.168.103.254
set DNS1=202.96.128.143
set DNS2=202.96.128.68
set WINS=192.168.103.254
for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "物理地址"') do set mac=%%i
for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "以太网适配器"')  do set Ethernet=%%k
for /f "tokens=1,2" %%i in ('more /e +21 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"&set "IP=%%j"
for /f "tokens=4" %%j in ('more /e +21 %0 ^|find /i "%mac:~,-1%"') do set "p=%%j"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
netsh interface ip set address "%Ethernet:~,-2%" static %IP% %Mask% %GATEWAY% 1 >nul 2>nul
netsh interface ip set dns "%Ethernet:~,-2%" static %DNS1% register=PRIMARY >nul 2>nul
netsh interface ip add dns "%Ethernet:~,-2%"  %DNS2% index=2 >nul 2>nul
netsh interface ip set wins "%Ethernet:~,-2%" static %WINS%  >nul 2>nul
exit
A01 192.168.103.101 10-60-4b-77-fe-a0 北三楼A01
A02 192.168.103.102 10-60-4b-8b-50-be 北三楼A02
A03 192.168.103.103 10-60-4b-88-61-7f 北三楼A03
A04 192.168.103.104 10-60-4b-88-70-a6 北三楼A04
A05 192.168.103.105 10-60-4B-89-46-CE 北三楼A05
A06 192.168.103.106 10-60-4b-8b-51-3f 北三楼A06
A07 192.168.103.107 10-60-4b-8b-53-cd 北三楼A07
A08 192.168.103.108 10-60-4b-8b-51-38 北三楼A08
A09 192.168.103.109 10-60-4b-77-e5-c4 北三楼A09
A10 192.168.103.110 10-60-4b-77-ea-c2 北三楼A10
B01 192.168.103.111 10-60-4b-77-e7-e6 北三楼B01
B02 192.168.103.112 10-60-4b-77-fe-80 北三楼B02
B03 192.168.103.113 10-60-4b-88-5e-cc 北三楼B03
B04 192.168.103.114 10-60-4b-77-ea-a9 北三楼B04
B05 192.168.103.115 10-60-4b-77-fe-9e 北三楼B05
B06 192.168.103.116 10-60-4b-77-e7-eb 北三楼B06
B07 192.168.103.117 10-60-4b-88-70-a1 北三楼B07
B08 192.168.103.118 10-60-4b-8b-50-99 北三楼B08
B09 192.168.103.119 10-60-4b-86-2f-d2 北三楼B09
B10 192.168.103.120 10-60-4b-77-fe-f4 北三楼B10

TOP

回复 3# Batcher


    改了还是没有用?是不是有多个“物理地址”,冲突了?IPCONFIG /ALL的内容见附件1.TXT

链接: https://pan.baidu.com/s/1ZFZWMXj7H9ZeJEIXC9oYaw 提取码: ee5v


@echo off
echo 正在配置IP地址、DNS请稍候……
set MASK=255.255.255.0
set GATEWAY=192.168.103.254
set DNS1=202.96.128.143
set DNS2=202.96.128.68
set WINS=192.168.103.254
for /f "tokens=12 delims= " %%i in ('ipconfig /all^|find /i "物理地址"') do set mac=%%i
for /f "tokens=1,2*" %%i in ('ipconfig /all^|find "以太网适配器"')  do set Ethernet=%%k
for /f "tokens=1,2" %%i in ('more /e +21 %0 ^|find /i "%mac:~,-1%"') do set "name=%%i"&set "IP=%%j"
for /f "tokens=4" %%j in ('more /e +21 %0 ^|find /i "%mac:~,-1%"') do set "p=%%j"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\parameters" /v srvcomment /t reg_sz /d %p% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName\ComputerName" /v ComputerName /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v "NV Hostname" /t reg_sz /d %name% /f >nul 2>nul
reg add "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters" /v Hostname /t reg_sz /d %name% /f >nul 2>nul
netsh interface ip set address "%Ethernet:~,-2%" static %IP% %Mask% %GATEWAY% 1 >nul 2>nul
netsh interface ip set dns "%Ethernet:~,-2%" static %DNS1% register=PRIMARY >nul 2>nul
netsh interface ip add dns "%Ethernet:~,-2%"  %DNS2% index=2 >nul 2>nul
netsh interface ip set wins "%Ethernet:~,-2%" static %WINS%  >nul 2>nul
exit
A01 192.168.103.101 10-60-4b-77-fe-a0 北三楼A01
A02 192.168.103.102 10-60-4b-8b-50-be 北三楼A02
A03 192.168.103.103 10-60-4b-88-61-7f 北三楼A03
A04 192.168.103.104 10-60-4b-88-70-a6 北三楼A04
A05 192.168.103.105 10-60-4B-89-46-CE 北三楼A05
A06 192.168.103.106 10-60-4b-8b-51-3f 北三楼A06
A07 192.168.103.107 10-60-4b-8b-53-cd 北三楼A07
A08 192.168.103.108 10-60-4b-8b-51-38 北三楼A08
A09 192.168.103.109 10-60-4b-77-e5-c4 北三楼A09
A10 192.168.103.110 10-60-4b-77-ea-c2 北三楼A10
B01 192.168.103.111 10-60-4b-77-e7-e6 北三楼B01
B02 192.168.103.112 10-60-4b-77-fe-80 北三楼B02
B03 192.168.103.113 10-60-4b-88-5e-cc 北三楼B03
B04 192.168.103.114 10-60-4b-77-ea-a9 北三楼B04
B05 192.168.103.115 10-60-4b-77-fe-9e 北三楼B05
B06 192.168.103.116 10-60-4b-77-e7-eb 北三楼B06
B07 192.168.103.117 10-60-4b-88-70-a1 北三楼B07
B08 192.168.103.118 10-60-4b-8b-50-99 北三楼B08
B09 192.168.103.119 10-60-4b-86-2f-d2 北三楼B09
B10 192.168.103.120 10-60-4b-77-fe-f4 北三楼B10

TOP

回复 6# Batcher


    能不能给个有用的代码?

TOP

回复 8# Batcher

我肯定搞不定的,代码都是复制的!

TOP

回复 9# jiavip

试了下,不行!

TOP

回复 15# WHY

TOP

回复 19# WHY


    可能是MAC搞错了,代码有效!谢谢!

TOP

回复 22# ygqiang


15楼代码!

TOP

本帖最后由 滴血雄鹰 于 2019-3-19 16:44 编辑

回复 15# WHY


    15楼的代码运行完后(修改计算机名和IP后),再打开a.exe,下面的代码放在pause & exit /b的前面么?
@echo off
start C:\a.exe

TOP

返回列表