如何检测网络接口是“初始化”

问题描述 投票:0回答:1

计算机从睡眠状态唤醒时,我的USB网络适配器(最新驱动程序)从控制面板中的“网络连接”窗口消失。因此,使用devcon构建批处理文件以重置适配器。适配器重置后,我想使用netsh以编程方式添加一些IP子网。问题是适配器在执行重置(禁用&&启用命令)后可能需​​要一些时间,因为如果比某些(比如6秒,使用旧的Atom CPU)时间更早启动netsh失败。现在我使用'timeout / T'命令插入了超时,但这次可能因系统负载而异。问题是:有没有办法从批处理文件以编程方式检测适配器状态?

set "netcmd=netsh in ip add address ETH1 192.168.0.100 255.255.255.0"
devcon disable "USB\VID_9710&PID_7830" >NUL 
devcon enable "USB\VID_9710&PID_7830" >NUL 
timeout /T 6 >NUL
%netcmd%
batch-file networking netsh devcon
1个回答
1
投票

netsh interface show interface name="Local Area Connection"显示如下:

Local Area Connection
   Type:                 Dedicated
   Administrative state: Enabled
   Connect state:        Disconnected

你可以用以下方式检查它的状态:

:loop
timeout 2
echo still waiting...
netsh interface show interface name="Local Area Connection" | find "Connect state" |find "Connected" >nul || goto :loop
echo Interface is now connected.

使用...find "Administrative state" |find "Enabled" ...可以完成相同的操作(取决于您引用的适配器状态)

注意:将Local Area Connection更改为适配器的名称

© www.soinside.com 2019 - 2024. All rights reserved.