区分虚拟网卡和物理网卡

  1. 枚举注册表网卡信息 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}
  2. 读取没一项的CharacteristicsNetCfgInstanceId信息
  3. Characteristics & NCF_PHYSICAL 即为物理网卡

在这里插入图片描述

Characteristics值
类型说明
NCF_VIRTUAL0x01组件是一个虚拟适配器
NCF_SOFTWARE_ENUMERATED0x02组件是一个软件模拟的适配器
NCF_PHYSICAL0x04组件是一个物理适配器
NCF_HIDDEN0x08组件不显示用户接口
NCF_NO_SERVICE0x10组件没有相关的服务(设 备驱动程序)
NCF_NOT_USER_REMOVABLE0x20组件不能被用户删除(例如,通过控制面板或设备管理器)
NCF_MULTIPORT_INSTANCED_ADAPTER0x40组件有多个端口,每个端口作为单独的设备安装。每个端口有自己的hw_id(组件ID)并可被单独安装,这只适合于EISA适配器
NCF_HAS_UI0x80组件支持用户接口(例如,Advanced Page或Customer Properties Sheet)
NCF_FILTER0x400组件是一个过滤器
NetCfgInstanceId(需要管理员权限)

PIP_ADAPTER_INFOAdapterName字段

	std::map<std::string, DWORD> netcard_control_info()
	{
		std::map<std::string, DWORD> ret_val;
		std::vector<std::string> vec_keys;
		Registry::EnumKey(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e972-e325-11ce-bfc1-08002be10318}"), vec_keys, false, true);

		for (auto& item : vec_keys)
		{
			std::string  NetCfgInstanceId;
			DWORD Characteristics;
			Registry::Read(HKEY_LOCAL_MACHINE, item.c_str(), "NetCfgInstanceId", NetCfgInstanceId);
			Registry::Read(HKEY_LOCAL_MACHINE, item.c_str(), "Characteristics", Characteristics);
			ret_val[NetCfgInstanceId] = Characteristics;
		}

		return ret_val;
	}

	bool is_virtual_netcard(const std::string& id, const std::map<std::string, DWORD>& flags)
	{
		if (flags.count(id))
		{
			DWORD dwflags = flags.at(id);
			return (~dwflags & 0x04) != 0;
		}
		return false;
	}

示例

std::map<std::string, DWORD> netcardc_info = netcard_control_info();
bool is_virtual = is_virtual_netcard(pIpAdapterInfo->AdapterName, netcardc_info);
  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值