java 判断虚拟网卡物理网卡
读取注册表方式,jregistrykey.jar与jregistrykey.dll.通过“characteristics”值确定虚拟网卡还是物理网卡。该值在注册表的位置HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\【连接索引号】\下
private static int*NCF_PHYSICAL* = 0x4;//组件是一个物理适配器
**private static int***NCF\_SOFTWARE\_ENUMERATED* = 0x2; //组件是一个软件模拟的适配器
**private static int***NCF\_VIRTUAL* = 0x1;//组件是个虚拟适配器
**private static int***NCF\_HIDDEN* = 0x8;//组件不显示用户接口
**private static int***NCF\_NO\_SERVICE* = 0x10;//组件没有相关的服务(设备驱动程序)
**private static int***NCF\_NOT\_USER\_REMOVABLE* = 0x20;//不能被用户删除(例如,通过控制面板或设备管理器)
**private static int***NCF\_MULTIPORT\_INSTANCED\_ADAPTER* = 0x40;//组件有多个端口,每个端口作为单独的设备安装。每个端口有自己的hw\_id(组件ID) 并可被单独安装,这只适合于EISA适配器
**private static int***NCF\_HAS\_UI* = 0x80;//组件支持用户接口(例如,Advanced Page或Customer Properties Sheet)
**private static int***NCF\_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
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());
}
}
}
还没有评论,来说两句吧...