Board logo

标题: [文本处理] [分享]批处理设置mac和ip [打印本页]

作者: shihao    时间: 2010-11-9 20:38     标题: [分享]批处理设置mac和ip

请“iawn1989”看下是不是可以
1。跟根据虚拟网卡在注册表的ComponentId或者是DriverDesc网卡名称。(补充一下,如果用批处理无法做到确定那张是虚拟网卡的情况下,可以扫描DriverDesc,然后列说本计算机所有的网卡,手动选择.1或者2)

2。如果递加难做得到比较易懂完善的,也可以参考读取文本mac的办法,读取一个IP [macip.txt 格式005056d00012=192.168.1.4]

3。不考虑decvon,需要重起

使用方法 test 255.255.255.0 192.168.1.2
  1. rem 下面是test.bat内容
  2. @echo off
  3. set mask=%1
  4. set gw=%2
  5. echo 正在读取网卡信息......
  6. for /f "delims=:" %%i in ('findstr /n . macip.txt') do set total=%%i
  7. set /a rnd=%random% %% %total%
  8. if %rnd% equ 0 set rnd=1
  9. for /f "tokens=1* delims=:" %%i in ('findstr /n .* macip.txt') do (if %%i equ %rnd% set macad=%%j)
  10. for /f "tokens=1,2 delims==" %%j in ("%macad%") do set mac=%%j&&set ip=%%k
  11. cd.>2.txt&cd.>s.txt
  12. regedit /e a.reg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}
  13. for /f "tokens=1,4 delims=," %%a in ('getmac /v /fo:csv /nh') do >>s.txt set/p=%%a<nul&>>s.txt set/p=";"<nul&for /f "tokens=2
  14. delims={" %%o in (%%b) do echo %%o>>s.txt
  15. findstr /n .* s.txt >3.txt
  16. for /f "delims=:" %%b in ('type a.reg ^| findstr /n ^[') do echo %%b>>2.txt
  17. echo .   
  18. echo  -----------------
  19. for /f "delims=;" %%a in (3.txt) do echo    %%a
  20. echo  -----------------
  21. SET Choice=
  22. SET /P Choice= 请选择网卡:
  23. for /f "tokens=1,2 delims=;" %%a in ('findstr "^%Choice%" 3.txt') do set kk=%%b&&for /f "tokens=2 delims=:" %%z in ("%%a") do
  24. set nicid=%%z
  25. :Getkey _key
  26. echo 正在 查找 注册表......
  27. for /f "tokens=1* delims=:" %%i in ('type a.reg ^| findstr /n %kk%') do (set ok=%%i)
  28. setlocal enabledelayedexpansion
  29. for /f %%k in (2.txt) do ( set /a dif=%%k-%ok% & if !dif! leq 0 set li=%%k)
  30. for /f "tokens=1* delims=:" %%i in ('type a.reg ^| findstr /n .*') do (if %%i equ !li! call :Makereg %%j)
  31. endlocal
  32. goto :eof
  33. :Makereg
  34. echo Windows Registry Editor Version 5.00 >changemac.reg
  35. echo.>>changemac.reg
  36. echo %1 >>changemac.reg
  37. echo "NetworkAddress"="%mac%">>changemac.reg
  38. echo 正在 设置 %nicid% 的MAC地址......
  39. reg import changemac.reg 1>nul
  40. if %errorlevel% equ 0 (echo  [%nicid% MAC地址设置为 %mac%] 处理完成) else (echo   [ MAC地址设置 失败 ]&goto :end)
  41. echo 正在 设置 %nicid% 的IP地址......
  42. netsh interface ip set address "%nicid%" static %ip% %mask% %gw% 1 >nul
  43. if %errorlevel% equ 0 (echo  [%nicid% IP地址设置为 %ip%] 处理完成) else (echo  [ IP地址设置 失败 ])
  44. goto :end
  45. :end
  46. del 2.txt&del 3.txt&del s.txt&del a.reg&del changemac.reg
复制代码

[ 本帖最后由 shihao 于 2010-11-10 09:55 编辑 ]




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2