Board logo

标题: [网络连接] 请问批处理如何提取多块网卡情况下的网关地址(ipconfig)? [打印本页]

作者: ultrasurf    时间: 2011-8-5 16:00     标题: 请问批处理如何提取多块网卡情况下的网关地址(ipconfig)?

本帖最后由 ultrasurf 于 2011-8-6 07:59 编辑

例如: ipconfig 显示的结果是:

Ethernet adapter VMware Network Adapter VMnet8:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.1.10
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . :192.168.1.1

Ethernet adapter VMware Network Adapter VMnet1:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.2.10
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . :192.168.2.1

Ethernet adapter 本地连接:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.3.10
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.3.1

Ethernet adapter 无线网络连接:

        Connection-specific DNS Suffix  . :
        IP Address. . . . . . . . . . . . : 192.168.4.10
        Subnet Mask . . . . . . . . . . . : 255.255.255.0
        Default Gateway . . . . . . . . . : 192.168.4.1


现在希望提取出 本地连接 和 无线网络连接 的网关地址(Default Gateway),不希望出现 VMware Network Adapter VMnet8 和 VMware Network Adapter VMnet1 的网关地址, 请问如何写bat呀。自己试了一下只写得出提取最后一个的,谢谢!
作者: xlybzk    时间: 2011-8-5 16:21

  1. ipconfig/all|findstr /i /v "Default Gateway"
复制代码

作者: Hello123World    时间: 2011-8-5 18:22

  1. ipconfig/all|findstr /i  "默认网关"
  2. ::适用于win7
复制代码
  1. ipconfig/all|findstr /i  /c:"Default Gateway"
  2. ::适用于xp
复制代码

作者: ultrasurf    时间: 2011-8-6 08:00

上面方法提取出来的是所有的defalut,我这边希望提取出 本地连接 和 无线网络连接 的网关地址(Default Gateway),不希望出现 VMware Network Adapter VMnet8 和 VMware Network Adapter VMnet1 的网关地址, 后续是用来写 iproute 的,谢谢~
作者: CUer    时间: 2011-8-6 10:53

  1. @echo off
  2. for /f "tokens=2 delims==" %%a in ('wmic nic where "NetConnectionID like '%%连接'" get Caption /value') do (
  3.     set cap=%%a
  4. )
  5. wmic NicConfig where "Caption='%cap%'" get DefaultIPGateway /value
  6. pause
复制代码





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