get physical network adapter

Kran2022 406 Reputation points
2022-12-01T08:50:22.903+00:00

Hi All Monring,
How can get the lis of network physical adapters? In case of Win32 we can identify PNI ID but what is the equivalent while using NetworkInterface class in c# .net?

From my below code i'm getting only Ethernet in the list but i have both Ethernet and Wireless card in my system; also i would like to exclude all the WAN & Cellulaire networks. Thanks

List<NetworkInterface> macaddresss = GetActualAdapters();  
cbox1.Items.Add(macaddresss); //combobox to add the network adapters  

public static List<NetworkInterface> GetActualAdapters()  
		{  
			try  
			{  
				return (from adapter in NetworkInterface.GetAllNetworkInterfaces()  
                        where adapter.NetworkInterfaceType != NetworkInterfaceType.Unknown  
                        where adapter.NetworkInterfaceType != NetworkInterfaceType.Tunnel  
                        where adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback  
						select adapter).ToList();  
			}  
			catch (Exception e)  
			{  
				Console.Write("Exception :{0}", e.ToString());  
				return new List<NetworkInterface>();  
			}  
		}  

266111-image.png

Developer technologies XAML
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,521 Reputation points
    2022-12-01T08:55:38.927+00:00

    You can see this thread Get the IP address of the physical network card ?
    (with HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards)


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.