🟣 C# / .NET 6+

Get Network Adapter Configuration Report (C#)

Queries Win32_NetworkAdapterConfiguration via WMI (System.Management) and prints Network Adapter Configuration to the console.

By WindowsScripting.com · 1.2 KB
GetNetworkAdapterConfigReport.cs
// GetNetworkAdapterConfigReport.cs
//
// Reports Network Adapter Configuration via WMI (Win32_NetworkAdapterConfiguration).
//
// Requires the System.Management package:
//   dotnet new console -o NetworkAdapterConfigReport
//   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 Description, IPAddress, DefaultIPGateway, DNSServerSearchOrder FROM Win32_NetworkAdapterConfiguration");
int count = 0;

foreach (ManagementObject item in searcher.Get())
{
    Console.WriteLine($"Description: {item["Description"]}");
    Console.WriteLine($"IPAddress: {item["IPAddress"]}");
    Console.WriteLine($"DefaultIPGateway: {item["DefaultIPGateway"]}");
    Console.WriteLine($"DNSServerSearchOrder: {item["DNSServerSearchOrder"]}");
    Console.WriteLine(new string('-', 40));
    count++;
}

if (count == 0)
{
    Console.WriteLine("No Network Adapter Configuration found.");
}
else
{
    Console.WriteLine($"\n{count} Network Adapter Configuration found.");
}