Board logo

标题: [文件操作] WIN7和XP下批处理如何从文本中列出的多组计算机名、IP和MAC随机读取一组应用到本机上 [打印本页]

作者: yajiu    时间: 2016-8-7 10:31     标题: WIN7和XP下批处理如何从文本中列出的多组计算机名、IP和MAC随机读取一组应用到本机上

用WIN7的 改计算机IP的批处理。在XP下。不能成功。

XP的要换另一种的命令的吗。
作者: GNU    时间: 2016-8-7 10:41

把你的文本压缩一下传上来我试试
作者: yajiu    时间: 2016-8-7 17:31

本帖最后由 yajiu 于 2016-8-9 14:47 编辑

楼下的贴是能成功的
作者: GNU    时间: 2016-8-7 22:00

回复 3# yajiu


@echo off
setlocal enabledelayedexpansion

set file=IP.txt
set line_num=0

for /f %%i in (%file%) do set /a line_num+=1

set /a "line=%random% %% %line_num%"
set /a line+=1

set line_num=0
for /f "tokens=1-3" %%i in (%file%) do (
    set /a line_num+=1
    if !line_num!==%line% (
        set "Var1=%%i"
        set "Var2=%%j"
        set "Var3=%%k"

        goto :EOF
    )
)
作者: yajiu    时间: 2016-8-8 04:09

本帖最后由 yajiu 于 2016-8-8 10:33 编辑

随机读取了i j k 三个变量成功了。 谢谢。非常感谢。GNU


经xxpinqz和GNU的指点。  改IP成功 。非常感谢。 现差机算机名和MAC 这两个变量的使用了。


已成功测试的代码
  1. setlocal enabledelayedexpansion
  2. set file=test.txt
  3. set line_num=0
  4. for /f %%i in (%file%) do set /a line_num+=1
  5. set /a "line=%random% %% %line_num%"
  6. set /a line+=1
  7. set line_num=0
  8. for /f "tokens=1-3" %%i in (%file%) do (
  9.     set /a line_num+=1
  10.     if !line_num!==%line% (
  11.         set "Var1=%%i"
  12.         set "Var2=%%j"
  13.         set "Var3=%%k"
  14.         echo %%i
  15.         echo %%j
  16.         echo %%k
  17. pause
  18.     )
  19. )
  20. set name=本地连接
  21. set ipint=ip
  22. set ip=%Var2%
  23. set mask=255.255.255.0
  24. set gateway=192.168.1.1
  25. set dns1=8.8.8.8
  26. set dns2=202.96.128.86
  27. echo %ip%
  28. pause
  29. set ipint=ipv4
  30. netsh interface %ipint% set address name="%name%" source=static addr=%ip% mask=%mask% gateway=%gateway% gwmetric=0
  31. netsh interface %ipint% set dns name="%name%" source=static addr=%dns1% register=primary
  32. netsh interface %ipint% add dns name="%name%" addr=%dns2% index=2
  33. pause
  34. ipconfig /all
复制代码

作者: ygqiang    时间: 2016-8-8 06:11

回复 5# yajiu


    addr=%Var2%
作者: yajiu    时间: 2016-8-8 07:41

本帖最后由 yajiu 于 2016-8-8 07:43 编辑
回复  yajiu


    addr=%Var2%
ygqiang 发表于 2016-8-8 06:11


测试了。不行。 大神们帮下。连续两天在学批处理了。5555好惨
作者: ygqiang    时间: 2016-8-8 08:15

本帖最后由 ygqiang 于 2016-8-8 08:16 编辑

回复 7# yajiu
  1. set name=本地连接
  2. set ipint=ip
  3. set ip=%Var2%
  4. set mask=255.255.255.0
  5. set gateway=192.168.1.1
  6. set dns1=8.8.8.8
  7. set dns2=114.114.114.114
  8. echo %ip%
  9. pause
  10. ver|find "5.2" >nul&&goto :continue||goto :Other
  11. :Other
  12. set ipint=ipv4
  13. :continue
  14. netsh interface %ipint% set address name="%name%" source=static addr=%ip% mask=%mask% gateway=%gateway% gwmetric=0
  15. netsh interface %ipint% set dns name="%name%" source=static addr=%dns1% register=primary
  16. netsh interface %ipint% add dns name="%name%" addr=%dns2% index=2
  17. pause&exit
复制代码

作者: GNU    时间: 2016-8-8 08:17

回复 5# yajiu


for循环内部可以用%%i %%j %%k
for循环外面需要用定义好的%Var1% %Var2% %Var3%
作者: yajiu    时间: 2016-8-8 08:32

本帖最后由 yajiu 于 2016-8-8 12:14 编辑

帮我改下。我真的是新手。在看紧。入门。 我怎么测试mac 都没成功。
  1. set networdaddress=mac
  2. set mac=%Var3%
  3. for /f "skip=1 delims=[]" %%i in ('wmic nic where 'netconnectionid like "本地连接%%"' get caption') do set numnet=%%i
  4. set regpath=HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\%numnet:~-4%
  5. reg add "%regpath%" /v "MAC Address" /d "%mac%" /f
  6. reg add "%regpath%\Ndi\Params\NetworkAddress" /ve /d "%%mac" /f
  7. reg add "%regpath%\Ndi\Params\NetworkAddress" /v "ParamDesc" /d "MAC Address"
复制代码

作者: xxpinqz    时间: 2016-8-8 09:11

回复 10# yajiu

删除23行的goto :eof
  1. @echo off
  2. set/an=%random%%%50+2
  3. for /f "tokens=2" %%a in ('findstr /n . ip.txt^|findstr /bc:"%n%:"')do (
  4.     echo,netsh int ipv4 set add .....%%a
  5.     echo,netsh int ipv4 set dns .....
  6. )
  7. pause
复制代码





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