标题: [网络连接] 批处理提取ipconfig/all输出中的DHCP-IP作route命令的输入参数? [打印本页]
作者: lrk 时间: 2008-12-7 03:46 标题: 批处理提取ipconfig/all输出中的DHCP-IP作route命令的输入参数?
RT,我有多网卡,希望提取ipconfig /all输出中的其中一块网卡的DHCP服务器IP,作为route命令的输入参数,不知能否实现?
查了一下,发现一个贴的问题跟我的非常的相似:
[求助]用何命令获取PPPoE拨号连接的IP?
我的问题是这样:
对于如图的IP设置,我要提取后面一块网卡的DHCP的IP:10.104.176.145,作为route命令的参数:
route add 0.0.0.0 mask 0.0.0.0 10.104.176.145
因为这个值是会变化的,所以想做个批处理可以动态更新路由表。
参照找到那个帖子的,我写了下面的语句,可是却不成功,各位帮下忙了:- for /f "tokens=1,2* delims=:" %%i in ('ipconfig /all') do (
- if /i "%%j"==" Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
- if defined flag (
- if "%%i "==" DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 %%j))
复制代码
作者: lrk 时间: 2008-12-7 08:00 标题: 返回信息
附上返回信息:
D:\temp\CMD>for /F "tokens=1,2* delims=:" %i in ('ipconfig /all') do (
if /I "%j" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
if defined flag (if "%i " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 %j )
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Host Name . . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 K-K-K
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Primary Dns Suffix . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Node Type . . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 Unknown
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " IP Routing Enabled. . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 No
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " WINS Proxy Enabled. . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 No
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if "Ethernet adapter Local Area Connection " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Connection-specific DNS Suffix . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Description . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 Realtek RTL8169/8
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Physical Address. . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 00-E0-4C-5B-28-F3
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Dhcp Enabled. . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 No
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " IP Address. . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 172.16.143.180
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Subnet Mask . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 255.255.255.0
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Default Gateway . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " DNS Servers . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 172.16.2.1
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if "Ethernet adapter {C254AFDB-E199-471E-AB9D-A6E7D08B36DA} " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0
)
D:\temp\CMD>(
if /I "" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
" == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 )
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Connection-specific DNS Suffix . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Description . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 Netpas Win32 Virt
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Physical Address. . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 00-FF-C2-54-AF-DB
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Dhcp Enabled. . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 Yes
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Autoconfiguration Enabled . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 Yes
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " IP Address. . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 10.104.176.146
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Subnet Mask . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 255.255.255.252
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " Default Gateway . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 10.104.176.145
)
D:\temp\CMD>(
" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
) defined flag (if " DHCP Server . . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 10.104.176.145
)
D:\temp\CMD>(
if /I " 2008年12月7日 7" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
if defined flag (if " Lease Obtained. . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 2008年12月7日 7 )
)
D:\temp\CMD>(
if /I " 2008年12月9日 7" == " Netpas Win32 Virtual Network Adapter - Packet Scheduler Miniport" set flag=a
if defined flag (if " Lease Expires . . . . . . . . . . " == " DHCP Server . . . . . . . . . . . " route -p add 0.0.0.0 mask 0.0.0.0 2008年12月9日 7 )
)
作者: Batcher 时间: 2008-12-7 11:49
- for /f "tokens=1,2* delims=:" %%i in ('ipconfig /all^|find "IP Address"') do (
- set IP=%%j
- )
- route -p add 0.0.0.0 mask 0.0.0.0 %IP%
复制代码
作者: lrk 时间: 2008-12-7 16:07
Batcher大:
非常多谢你的回复!我看了你的代码,觉得你理解错我的问题了,你的代码是把当前的IP地址作为后面命令的参数输入,是这样吧?我其实是想把DHCP服务器的IP作为参数输入。
我把“IP Address”改成“DHCP Server”,成功执行了。
不过有个小问题,就是我是双网卡的,刚好我的第一块网卡没有使用DHCP,上面没有错误。我想问一下,如果我的第一块网卡也使用了DHCP,那是不是没法选择那块网卡的DHCPIP了?
另外,我一楼改写的代码尝试去定位网卡再提取,可为什么不成功呢?还是批处理新手,希望解决这个问题学习下,呵呵!
作者: Batcher 时间: 2008-12-7 18:00 标题: 回复 4楼 的帖子
第一块网卡的DHCP:- @echo off
- for /f "tokens=1,2* delims=:" %%i in ('ipconfig /all^|find "DHCP Server"') do (
- set IP=%%j
- route -p add 0.0.0.0 mask 0.0.0.0 %IP%
- goto :eof
- )
复制代码
最后一块网卡的DHCP:- @echo off
- for /f "tokens=1,2* delims=:" %%i in ('ipconfig /all^|find "DHCP Server"') do (
- set IP=%%j
- )
- route -p add 0.0.0.0 mask 0.0.0.0 %IP%
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |