可利用IPHELPAPI进行获取
MIB_IFROW Info ; // 存放获取到的Adapter参数
memset(&Info ,0 ,sizeof(MIB_IFROW)) ;
Info.dwIndex = dwIndex ; // dwIndex是需要获取的Adapter的索引,可以通过GetAdaptersInfo和其他相关函数获取
if(GetIfEntry(&Info) != NOERROR){
printf("ErrorCode = %d\n" ,GetLastError()) ;
return ;
}
MIB_IFROW 中有一项 dwOperStatus的参数,它表明当前接口的操作状态
其值如下:
Value Meaning
IF_OPER_STATUS_NON_OPERATIONAL
LAN adapter has been disabled, for example because of an address conflict.
局域网适配器禁用,例如地址冲突
IF_OPER_STATUS_UNREACHABLE
WAN adapter that is not connected.
WAN适配器未连接
IF_OPER_STATUS_DISCONNECTED
For LAN adapters: network cable disconnected. For WAN adapters: no carrier
局域网适配器:网线未插入。WAN适配器:无信号
IF_OPER_STATUS_CONNECTING
WAN adapter that is in the process of connecting.
IF_OPER_STATUS_CONNECTED
WAN adapter that is connected to a remote peer.
已连接远端
IF_OPER_STATUS_OPERATIONAL
Default status for LAN adapters 默认状态
参考:ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.chs/iphlp/iphlp/getifentry.htm
经测试
拔下网线时,dwOperStatus 值为IF_OPER_STATUS_NON_OPERATIONAL
连接网线时,dwOperStatus 值为IF_OPER_STATUS_OPERATIONAL