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

[文本处理] 根据自动获取的IP、DNS设置成固定,并自动识别网卡名称

前半部分已经解决,网卡名称这部分是在头痛,以下是前半部分:
  1. @echo off
  2. ipconfig>ipc.txt
  3. netsh interface ip show address>gwc.txt
  4. for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a
  5. for /f "delims=: tokens=2" %%b in ('find "子网掩码" ipc.txt') do set mask=%%b
  6. for /f "delims=: tokens=2" %%i in ('find "默认网关" gwc.txt') do set gw=%%i
  7. netsh interface ip set address "本地连接" static %IP% %mask% %gw% 0
  8. netsh interface ip set dns name="本地连接" source=static addr=10.46.20.96
  9. netsh interface ip add dns name="本地连接" addr=10.46.20.97 index=2
  10. del ipc.txt
  11. del gwc.txt
复制代码
各位大神有没有办法,本地连接能够自动识别,好多电脑名称都不一样,有本地连接1~5都碰到过

情况比较复杂,遇到过电脑有4块板载网卡和1块外置USB无线网卡
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

本地连接一般只有一个,但是后面的数字就不一定是几了

TOP

用序列递增变量,获取时用 for /l 获取这些变量
这么好的论坛你上哪找,运行测试环境为6.1.7601-64
注:请遵守互联网信息安全,勿用于非法用途

TOP

回复 3# duduchong


    我们这边的实际情况是有几块板载网卡就有几个本地链接x
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

可能是我没表达清楚,我需要使用的电脑上,只有一个本地连接,但是本地连接后面有数字,有些电脑是2,有些是4,所以不需要区别

TOP

不需要区别,就先把无效的本地连接全部删除,然后你随便搞了。

TOP

哪位大哥帮我改改,获取名称啊

TOP

用了个很SB的办法解决了
@echo off

ipconfig>ipc.txt

netsh interface ip show address>gwc.txt

for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a

for /f "delims=: tokens=2" %%b in ('find "子网掩码" ipc.txt') do set mask=%%b

for /f "delims=: tokens=2" %%i in ('find "默认网关" gwc.txt') do set gw=%%i

netsh interface ip set address "本地连接" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地连接" source=static addr=10.46.20.96

netsh interface ip add dns name="本地连接" addr=10.46.20.97 index=2

netsh interface ip set address "本地连接 2" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地连接 2" source=static addr=10.46.20.96

netsh interface ip add dns name="本地连接 2" addr=10.46.20.97 index=2

netsh interface ip set address "本地连接 3" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地连接 3" source=static addr=10.46.20.96

netsh interface ip add dns name="本地连接 3" addr=10.46.20.97 index=2

netsh interface ip set address "本地连接 4" static %IP% %mask% %gw% 0

netsh interface ip set dns name="本地连接 4" source=static addr=10.46.20.96

netsh interface ip add dns name="本地连接 4" addr=10.46.20.97 index=2

netsh interface ip set address "以太网" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太网" source=static addr=10.46.20.96

netsh interface ip add dns name="以太网" addr=10.46.20.97 index=2

netsh interface ip set address "以太网 2" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太网 2" source=static addr=10.46.20.96

netsh interface ip add dns name="以太网 2" addr=10.46.20.97 index=2

netsh interface ip set address "以太网 3" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太网 3" source=static addr=10.46.20.96

netsh interface ip add dns name="以太网 3" addr=10.46.20.97 index=2

netsh interface ip set address "以太网 4" static %IP% %mask% %gw% 0

netsh interface ip set dns name="以太网 4" source=static addr=10.46.20.96

netsh interface ip add dns name="以太网 4" addr=10.46.20.97 index=2

del ipc.txt

del gwc.txt

TOP

  1. @echo off
  2. ipconfig>ipc.txt
  3. netsh interface ip show address>gwc.txt
  4. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionStatus='2'" get NetConnectionID /value^|find "="') do set %%A
  5. echo NetConnectionID="%NetConnectionID%"
  6. for /f "tokens=*" %%A in ('wmic nic where "NetConnectionID='%NetConnectionID%'" get index  /value^|find "="') do set %%A
  7. echo index="%index%"
  8. for /f "delims=: tokens=2" %%a in ('find "IPv4 地址" ipc.txt') do set IP=%%a
  9. for /f "delims=: tokens=2" %%b in ('find "子网掩码" ipc.txt') do set mask=%%b
  10. for /f "delims=: tokens=2" %%i in ('find "默认网关" gwc.txt') do set gw=%%i
  11. netsh interface ip set address "%NetConnectionID%" static %IP% %mask% %gw% 0
  12. netsh interface ip set dns name="%NetConnectionID%" source=static addr=10.46.20.96
  13. netsh interface ip add dns name="%NetConnectionID%" addr=10.46.20.97 index=2
  14. netsh interface set interface "%NetConnectionID%" disabled
  15. netsh interface set interface "%NetConnectionID%" enable
  16. del ipc.txt
  17. del gwc.txt
复制代码

TOP

返回列表