我们的电脑上现在可是很多的网卡,因为存在虚拟网卡,Lan口和wifi网卡等等。
之前有人给出判断的前缀,但是不够完整。可以从这里下载完整的资料。
1)先由 GetAdaptersInfo 获取所有网卡的基本信息。然后利用网卡名去注册表中查找对应的硬件信息。若是物理网卡,其硬件信息中通常会包含 PCI 。
说明:之前还有一些方法比如用pbws32.dll和api来获取hostame,hostip再获取mac,实际上只能取到一个mac。而GetAdaptersInfo可以获取所有。很实用。
例如,某个网卡的名为 {ACA306D0-1D69-4116-BC2B-919B428AD084}。
他在注册表中的信息所在位置为:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Network/{4D36E972-E325-11CE-BFC1-08002BE10318}/{ACA306D0-1D69-4116-BC2B-919B428AD084}/Connection
若PnpInstanceID的值以PCI开头,说明是物理网卡,MediaSubType为01则是常见网卡,02为无线网卡。
说明:其实这个方法挺好!!!而下面的方法感觉还是很勉强。有个错误
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Network的斜杠应该为反斜杠。
2)判断常用的虚拟网卡的前缀,比如vmware的虚拟网卡我们通常知道。ipconfig/all就能查到
"00:05:69"; //vmware1
"00:0C:29"; //vmware2
"00:50:56"; //vmware3
"00:1c:14"; //vmware4
"00:1C:42"; //parallels1
"00:03:FF"; //microsoft virtual pc
"00:0F:4B"; //virtual iron 4
"00:16:3E"; //red hat xen , oracle vm , xen source, novell xen
"08:00:27"; //virtualbox
我补充几个:
“08-00-58”;//Array Networks VP N Adapter
"00-FF-73"; //Sangfor SSL V P N CS Support System VNIC
所以还有其他的需要自己的归纳总结
// V P N, virtualization, tethering, bluetooth, etc.
static const InvalidMacEntry kInvalidAddresses[] = {
// Empty address
{MAC_LENGTH, {0, 0, 0, 0, 0, 0}},
// VMware
{OUI_LENGTH, {0x00, 0x50, 0x56}},
{OUI_LENGTH, {0x00, 0x05, 0x69}},
{OUI_LENGTH, {0x00, 0x0c, 0x29}},
{OUI_LENGTH, {0x00, 0x1c, 0x14}},
// VirtualBox
{OUI_LENGTH, {0x08, 0x00, 0x27}},
// PdaNet
{MAC_LENGTH, {0x00, 0x26, 0x37, 0xbd, 0x39, 0x42}},
// Cisco AnyConnect V P N
{MAC_LENGTH, {0x00, 0x05, 0x9a, 0x3c, 0x7a, 0x00}},
// Marvell sometimes uses this as a dummy address
{MAC_LENGTH, {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}},
// Apple uses this across machines for Bluetooth ethernet adapters.
{MAC_LENGTH-1, {0x65, 0x90, 0x07, 0x42, 0xf1}},
// Juniper uses this for their Virtual Adapter, the other 4 bytes are
// reassigned at every boot. 00-ff-xx is not assigned to anyone.
{2, {0x00, 0xff}},
// T-Mobile Wireless Ethernet
{MAC_LENGTH, {0x00, 0xa0, 0xc6, 0x00, 0x00, 0x00}},
// Generic Bluetooth device
{MAC_LENGTH, {0x00, 0x15, 0x83, 0x3d, 0x0a, 0x57}},
// RAS Async Adapter
{MAC_LENGTH, {0x20, 0x41, 0x53, 0x59, 0x4e, 0xff}},
// Qualcomm USB ethernet adapter
{MAC_LENGTH, {0x00, 0xa0, 0xc6, 0x00, 0x00, 0x00}},
// Windows V P N
{MAC_LENGTH, {0x00, 0x53, 0x45, 0x00, 0x00, 0x00}},
// Bluetooth
{MAC_LENGTH, {0x00, 0x1f, 0x81, 0x00, 0x08, 0x30}},
{MAC_LENGTH, {0x00, 0x1b, 0x10, 0x00, 0x2a, 0xec}},
{MAC_LENGTH, {0x00, 0x15, 0x83, 0x15, 0xa3, 0x10}},
{MAC_LENGTH, {0x00, 0x15, 0x83, 0x07, 0xC6, 0x5A}},
{MAC_LENGTH, {0x00, 0x1f, 0x81, 0x00, 0x02, 0x00}},
{MAC_LENGTH, {0x00, 0x1f, 0x81, 0x00, 0x02, 0xdd}},
// Ceton TV tuner
{MAC_LENGTH, {0x00, 0x22, 0x2c, 0xff, 0xff, 0xff}},
// Check Point V P N
{MAC_LENGTH, {0x54, 0x55, 0x43, 0x44, 0x52, 0x09}},
{MAC_LENGTH, {0x54, 0xEF, 0x14, 0x71, 0xE4, 0x0E}},
{MAC_LENGTH, {0x54, 0xBA, 0xC6, 0xFF, 0x74, 0x10}},
// Cisco V P N
{MAC_LENGTH, {0x00, 0x05, 0x9a, 0x3c, 0x7a, 0x00}},
// Cisco V P N
{MAC_LENGTH, {0x00, 0x05, 0x9a, 0x3c, 0x78, 0x00}},
// Intel USB cell modem
{MAC_LENGTH, {0x00, 0x1e, 0x10, 0x1f, 0x00, 0x01}},
// Microsoft tethering
{MAC_LENGTH, {0x80, 0x00, 0x60, 0x0f, 0xe8, 0x00}},
// Nortel V P N
{MAC_LENGTH, {0x44, 0x45, 0x53, 0x54, 0x42, 0x00}},
// AEP V P N
{MAC_LENGTH, {0x00, 0x30, 0x70, 0x00, 0x00, 0x01}},
// Positive V P N
{MAC_LENGTH, {0x00, 0x02, 0x03, 0x04, 0x05, 0x06}},
// Bluetooth
{MAC_LENGTH, {0x00, 0x15, 0x83, 0x0B, 0x13, 0xC0}},
// Kerio Virtual Network Adapter
{MAC_LENGTH, {0x44, 0x45, 0x53, 0x54, 0x4f, 0x53}},
// Sierra Wireless cell modems.
{OUI_LENGTH, {0x00, 0xA0, 0xD5}},
// FRITZ!web DSL
{MAC_LENGTH, {0x00, 0x04, 0x0E, 0xFF, 0xFF, 0xFF}},
// VirtualPC
{MAC_LENGTH, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}},
// Bluetooth
{MAC_LENGTH, {0x00, 0x1F, 0x81, 0x00, 0x01, 0x00}},
{MAC_LENGTH, {0x00, 0x30, 0x91, 0x10, 0x00, 0x26}},
{MAC_LENGTH, {0x00, 0x25, 0x00, 0x5A, 0xC3, 0xD0}},
{MAC_LENGTH, {0x00, 0x15, 0x83, 0x0C, 0xBF, 0xEB}},
// Huawei cell modem
{MAC_LENGTH, {0x58, 0x2C, 0x80, 0x13, 0x92, 0x63}},
// Fortinet V P N
{OUI_LENGTH, {0x00, 0x09, 0x0F}},
// Realtek
{MAC_LENGTH, {0x00, 0x00, 0x00, 0x00, 0x00, 0x30}},
// Other rare dupes.
{MAC_LENGTH, {0x00, 0x11, 0xf5, 0x0d, 0x8a, 0xe8}}, // Atheros
{MAC_LENGTH, {0x00, 0x20, 0x07, 0x01, 0x16, 0x06}}, // Atheros
{MAC_LENGTH, {0x0d, 0x0b, 0x00, 0x00, 0xe0, 0x00}}, // Atheros
{MAC_LENGTH, {0x90, 0x4c, 0xe5, 0x0b, 0xc8, 0x8e}}, // Atheros
{MAC_LENGTH, {0x00, 0x1c, 0x23, 0x38, 0x49, 0xa4}}, // Broadcom
{MAC_LENGTH, {0x00, 0x12, 0x3f, 0x82, 0x7c, 0x32}}, // Broadcom
{MAC_LENGTH, {0x00, 0x11, 0x11, 0x32, 0xc3, 0x77}}, // Broadcom
{MAC_LENGTH, {0x00, 0x24, 0xd6, 0xae, 0x3e, 0x39}}, // Microsoft
{MAC_LENGTH, {0x00, 0x0f, 0xb0, 0x3a, 0xb4, 0x80}}, // Realtek
{MAC_LENGTH, {0x08, 0x10, 0x74, 0xa1, 0xda, 0x1b}}, // Realtek
{MAC_LENGTH, {0x00, 0x21, 0x9b, 0x2a, 0x0a, 0x9c}}, // Realtek
}; //这个里面收集了很多,但是也是不会很全的。
我想其实也可以做到一个table(数据库系统)或者一个配置文件中去。这样可以不修改程序而满足不断的添加需要。