🟣 C# / .NET 6+
Get Network Adapters Report (C#)
Queries Win32_NetworkAdapter via WMI (System.Management) and prints Network Adapters to the console.
GetNetworkAdapterReport.cs
// GetNetworkAdapterReport.cs
//
// Reports Network Adapters via WMI (Win32_NetworkAdapter).
//
// Requires the System.Management package:
// dotnet new console -o NetworkAdapterReport
// dotnet add package System.Management
// (replace the generated Program.cs with this file, then dotnet run)
// On .NET Framework, System.Management is already available — just
// add a reference to it in your project.
using System;
using System.Management;
var searcher = new ManagementObjectSearcher("SELECT Name, MACAddress, AdapterType, NetEnabled FROM Win32_NetworkAdapter");
int count = 0;
foreach (ManagementObject item in searcher.Get())
{
Console.WriteLine($"Name: {item["Name"]}");
Console.WriteLine($"MACAddress: {item["MACAddress"]}");
Console.WriteLine($"AdapterType: {item["AdapterType"]}");
Console.WriteLine($"NetEnabled: {item["NetEnabled"]}");
Console.WriteLine(new string('-', 40));
count++;
}
if (count == 0)
{
Console.WriteLine("No Network Adapters found.");
}
else
{
Console.WriteLine($"\n{count} Network Adapters found.");
}