请参见下面windows中的ipconfig输出。
C:>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection 11:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::4149:4c25:692d:dfec%91
IPv4 Address. . . . . . . . . . . : 10.252.26.84
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Wireless LAN adapter Wireless Network Connection 15:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter Local Area Connection 10:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter Wireless Network Connection 14:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::79a2:afc8:7cd0:79ac%72
IPv4 Address. . . . . . . . . . . : 192.168.10.9
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.10.1我希望在bat文件中找到无线网络连接的默认网关14,然后将其存储在变量中供以后使用
我知道我可以“查找”,但是我不知道如何获得NIC的默认网关。
谢谢!
发布于 2011-11-04 03:35:23
使用以下方法验证接口名称:
netsh interface ip show address试着做这样的事:
@echo off
for /f "tokens=2 delims=:" %%g in ('netsh interface ip show address
"Wireless Network Connection 14" ^| findstr "Default"') do
set DefaultGateway=%%g
echo %DefaultGateway%
pause发布于 2012-03-16 17:08:23
这应该能得到:
wmic nicconfig where "description like '%wireless%'" get caption, defaultipgateway发布于 2011-11-03 16:08:15
尝试一些类似于:
@For /f "tokens=3" %%* in (
'route.exe print ^|findstr "\<0.0.0.0\>"'
) Do @Set "DefaultGateway=%%*"然后,您应该能够使用%DefaultGateway%作为变量。
来源
https://serverfault.com/questions/327448
复制相似问题