如果您正在寻找命令行实用程序ipconfig可以提供的信息,您应该使用System.Net.NetworkInformation命名空间。
此示例代码将枚举所有网络接口并转储每个适配器已知的地址。
using System;
using System.Net;
using System.Net.NetworkInformation;
class Program
{
static void Main(string[] args)
{
foreach (NetworkInterface netif in NetworkInterface.GetAllNetworkInterfaces())
{
Console.WriteLine("Network Interface: {0}", netif.Name);
IPInterfaceProperties properties = netif.GetIPProperties();
foreach (IPAddress dns in properties.DnsAddresses)
Console.WriteLine("\tDNS: {0}", dns);
foreach (IPAddressInformation anycast in properties.AnycastAddresses)
Console.WriteLine("\tAnyCast: {0}", anycast.Address);
foreach (IPAddressInformation multicast in properties.MulticastAddresses)
Console.WriteLine("\tMultiCast: {0}", multicast.Address);
foreach (IPAddressInformation unicast in properties.UnicastAddresses)
Console.WriteLine("\tUniCast: {0}", unicast.Address);
}
}
}
您可能最感兴趣的是UnicastAddresses。