java 判断虚拟网卡物理网卡

读取注册表方式,jregistrykey.jar与jregistrykey.dll.通过“characteristics”值确定虚拟网卡还是物理网卡。该值在注册表的位置HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\【连接索引号】\

   private static intNCF_PHYSICAL = 0x4;//组件是一个物理适配器

    private static intNCF_SOFTWARE_ENUMERATED = 0x2; //组件是一个软件模拟的适配器

    private static intNCF_VIRTUAL = 0x1;//组件是个虚拟适配器

    private static intNCF_HIDDEN = 0x8;//组件不显示用户接口

    private static intNCF_NO_SERVICE = 0x10;//组件没有相关的服务(设备驱动程序)

    private static intNCF_NOT_USER_REMOVABLE = 0x20;//不能被用户删除(例如,通过控制面板或设备管理器)

    private static intNCF_MULTIPORT_INSTANCED_ADAPTER = 0x40;//组件有多个端口,每个端口作为单独的设备安装。每个端口有自己的hw_id(组件ID) 并可被单独安装,这只适合于EISA适配器

    private static intNCF_HAS_UI = 0x80;//组件支持用户接口(例如,Advanced PageCustomer Properties Sheet)

    private static intNCF_FILTER = 0x400;//组件是一个过滤器

根据Characteristics值当

如果是虚拟网卡:Characteristics& NCF_VIRTUAL ==NCF_VIRTUAL

如果是物理网卡:Characteristics& NCF_PHYSICAL ==NCF_PHYSICAL

该方式会把微软回环网卡也取到,所以应添加用户接口判断,去掉环回网卡。

物理网卡:Characteristics& NCF_PHYSICAL ==NCF_PHYSICAL && Characteristics &NCF_HAS_UI ==NCF_HAS_UI

private static String PATH = "SYSTEM\\\\ControlSet001\\\\Control\\\\Class\\\\{4d36e972-e325-11ce-bfc1-08002be10318}";
private static String WLAN_PATH ="\\Ndi\\Interfaces";

/** * 获取子健集合

* @param str
* @return
*/
public List getReKeyList(String str) {
List<String> list = new ArrayList<String>();
RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE,str);  
if(r.hasSubkeys()) {  
  Iterator i = r.subkeys();  
  while(i.hasNext()) {  
     RegistryKey x = (RegistryKey)i.next();  
     list.add(x.getPath());
  } 

return list;
}



/**
* 读取键值
*/
public String getReValueByPath(String path,String key) {
String str ="";
RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, path); 
if(r.hasValue(key)) {  
  RegistryValue v = r.getValue(key);  
  str = v.getData().toString();
}
return str;
}


/**
* 枚举某键的所有值
* @param path
*/
public void listValueForKey(String path) {
RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, path);  
if(r.hasValues()) {  
  Iterator i = r.values();  
  while(i.hasNext()) {  
     RegistryValue v = (RegistryValue)i.next();  
     System.out.println(v.toString());  
  }  

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值