日期:2014-05-16 浏览次数:21068 次
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接
if (Pd1)
{
Console.WriteLine("网络适配器名称:" + adapter.Name);
Console.WriteLine("网络适配器标识符:" + adapter.Id);
Console.WriteLine("适配器连接状态:" + adapter.OperationalStatus.ToString());
IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息
if (ip.UnicastAddresses.Count > 0)
{
Console.WriteLine("IP地址:" + ip.UnicastAddresses[0].Address.ToString());
Console.WriteLine("子网掩码:" + ip.UnicastAddresses[0].IPv4Mask.ToString());
}
if (ip.GatewayAddresses.Count > 0)
{
Console.WriteLine("默认网关:" + ip.GatewayAddresses[0].Address.ToString()); //默认网关
}
int DnsCount = ip.DnsAddress