Gets the network card MAC address, physical address of the current active state
WMIC commands:win32_networkadapter and Win32_NetworkAdapterConfiguration.
Where the cmd command line executes:
1. Wmic Path win32_networkadapter get Guid,macaddress,netenabled,physicaladapter, Index
Note:
GUID: Connection unique identifier;
MACAddress: Network card address;
Netenabled: Whether the adapter is enabled, True is enabled, false is disabled;
Physicaladapter: Whether the adapter is a physical or logical adapter, true for physics, false for logic;
Index: The number of the network adapter that is stored in the system registry. Registry Path win32registry| system\\currentcontrolset\\control\\class\\{4d36e972-e325-11ce-bfc1-08002be10318}.
MSDN Address:
https://msdn.microsoft.com/en-us/library/aa394216 (v=vs.85). aspx
Requirements:
Minimum Supported Client |
Windows Vista |
Minimum Supported Server |
Windows Server 2008 |
Namespace |
root\cimv2 |
Mof |
Cimwin32.mof |
Dll |
CIMWin32.dll |
2. Wmic Path Win32_NetworkAdapterConfiguration get ipenabled,macaddress,settingid, IPAddress, Ipsubnet,index
Note:
IPEnabled: Whether the adapter is enabled, True is enabled, false is disabled;
MACAddress: Network card address;
Settingid: Connection unique identification;
IPADDRESS:IP address;
IPSubnet: Subnet mask;
Index:windows the index number of the network adapter configuration that is used when there are multiple configurations. Registry Path win32registry| SYSTEM\\CURRENTCONTROLSET\\CONTROL\\CLASS\\{4D36E972-E325-11CE-BFC1-08002BE10318};
MSDN Address:
https://msdn.microsoft.com/en-us/library/aa394217 (v=vs.85). aspx#
Requirements:
Minimum Supported Client |
Windows Vista |
Minimum Supported Server |
Windows Server 2008 |
Namespace |
root\cimv2 |
Mof |
Cimwin32.mof |
Dll |
CIMWin32.dll |
Parameter matching relationship:
Win32_NetworkAdapter |
Win32_NetworkAdapterConfiguration |
Guid |
Settingid |
Netenabled |
IPEnabled |
MACAddress |
MACAddress |
Index |
Index |
Differentiate between physical and virtual network cards
through the characteristics "This value determines whether the network card type is a virtual network card or a physical network card.
characteristics value in the registry at Hkey_local_machine\system\controlset001\control\class\{4d36e972-e325-11ce-bfc1-08002be10318}\ "Connection index number" \ under, in Windows, the value of characteristics is as follows, and the characteristics entry can have 1 or more values as follows (the sum should be computed for multiple values): "Remarks: Confirmed under Windows7 and WINDOWS10, Characteristics is a DWORD, it is not possible to multiple values here, and the computed sum is temporarily unknown. "
0x1 |
Ncf_virtual |
Description component is a virtual adapter |
0x2 |
ncf_software_enumerated |
Description component is an adapter for software emulation |
0x4 |
Ncf_physical |
Description component is a physical adapter |
0x8 |
Ncf_hidden |
Description component does not display the user interface |
0x10 |
Ncf_no_service |
Description component does not have a related service (device driver) |
0x20 |
Ncf_not_user_removable |
Description cannot be deleted by user (for example, via Control Panel or Device Manager) |
0x40 |
Ncf_multiport_instanced_adapter |
The description component has multiple ports, and each port is installed as a separate device. Each port has its own hw_id (component ID) and can be installed separately, which is only suitable for EISA adapters |
0x80 |
ncf_has_ui |
Description component supports user interface (for example, Advanced page or Customer Properties Sheet) |
0x400 |
Ncf_filter |
Description component is a filter |
If it is a virtual network card: Characteristics & ncf_virtual ==ncf_virtual
If it is a physical network card: Characteristics & ncf_physical ==ncf_physical
Example:
The value of characteristics is 0x84, then 0x84&0x4=0x4, which means that the NIC is a physical network card.
Note:
This method is tested on the physical machine, and can be separated from the network and virtual network card, but the physical network card can be found in the virtual machine system.
Reference Address:
http://blog.csdn.net/jianghui3132749/article/details/4868350
Summarize:
Gets the current active physical NIC address, which can be used directly with win32_networkadapter,win32_networkadapterconfiguration as a reference comparison. In addition, the command supports a minimum version of the system with limited Windows Vista and above, server version Windows Server 2008 and above.
Determine the wireless card and the wired network card
1. registry path: Hklm\system\currentcontrolset\control\network\{4d36e972-e325-11ce-bfc1-08002be10318}\ " Connection Unique identifier "\connection
The key value under the path: Mediasubtype, if value=2, represents the wireless network card.
2. Registry path: hkey_local_machine\system\controlset001\control\class\{ 4d36e972-e325-11ce-bfc1-08002be10318}\ "Connection index number" \ndi\interfaces
Key value under Path: LowerRange, if value contains WiFi or WLAN, (two devices verified value= "Wlan,ethernet,vwifi"), indicating the wireless network card.
Summary: If the above two methods determine whether the standard of wireless network card, for the applicability of the standard, special circumstances, such as VPN, virtual network card and so on whether the situation has a good support, still need to be verified . In addition, 3G network card is not yet in the judging standard, temporarily does not support.
Note: The wireless virtual network card created by the "Netsh wlan set hostednetwork mode=allow Ssid=simnovo key=simnovowifi" command is verified as a wireless network card under the judging conditions. But combined with the value of characteristics to determine the physical network card, you can distinguish the network card is a wireless virtual network card.
With the condition of the physical network card and the condition of the wireless network card, it is relatively stable to use WMIC and the registry method.
Judging process
1. Win7 above device: execute WMIC Path win32_networkadapter get Guid,macaddress,netenabled,physicaladapter,index, Gets the items netenabled and Physicaladapter are true. Where netenabled gets the true is in order to get the NIC currently in use. The GUID is the connection unique identifier, and index is the connection index number.
XP device: because XP does not support the Win32_NetworkAdapter partial field, the WMIC Path Win32_NetworkAdapterConfiguration get ipenabled is used, Macaddress,settingid, IPAddress, Ipsubnet,index, gets ipenabled to True, where, IPEnabled gets the true is in order to get the NIC currently in use. Settingid is the connection unique identifier, and index is the connection index number.
2. According to the connection index number obtained in 1, the registry path "hkey_local_machine\system\controlset001\control\class\{ 4d36e972-e325-11ce-bfc1-08002be10318}\ "Connection index number" \ ", Judge characteristics, filter out the physical network card
3. According to the physical network card obtained in 2, using the method of judging the cable network card and the wireless network card to filter, obtain the final current use of the network card is wired physical network card or wireless physical network card.
Verify the result "The picture is small, click the link to see"
Lenovo win8.1 WIFI "right"
Lenovo Win8 WIFI "right"
Samsung Win8 WIFI "right"
XPE wired "correct"
Lenovo Win7 Wired "right"
WIN10 wired "correct"
HP wired "correct"
HP wifi "correct"
HP 3G: "Error"
The distinction between wired network card and wireless network card, physical network card and virtual network card