using System;
using Microsoft.Win32;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RegistryKey start = Registry.LocalMachine;
            RegistryKey cardServiceName, networkKey;
            string networkcardKey = "SOFTWARE\\Microsoft\\Windows NT\\ CurrentVersion\\NetworkCards";
            string serviceKey = "SYSTEM\\CurrentControlSet\\Services";
            string networkcardKeyName, deviceName;
            string deviceServiceName, serviceName;
            RegistryKey ServiceName = start.OpenSubKey(networkcardKey);
            if (ServiceName == null)
            {
                Console.WriteLine("错误的关键字1");
                return;
            }
            string[] networkCards = ServiceName.GetSubKeyNames();
            ServiceName.Close();
            foreach (string KeyName in networkCards)
            {
                networkcardKeyName = networkcardKey + "\\" + KeyName;
                cardServiceName = start.OpenSubKey(networkcardKeyName);
                if (cardServiceName == null)
                {
                    Console.WriteLine("错误的关键字2:{0}",networkcardKeyName);
                }
                return;
                deviceServiceName=(string)cardServiceName.GetValue("serviceName");
                deviceName = (string)cardServiceName.GetValue("Dedcription");
                Console.WriteLine("\n网卡:{0}", deviceName);
                serviceName = serviceKey + deviceServiceName + "\\Parameters\\Tcpip";
                networkKey = start.OpenSubKey(serviceKey);
                if (networkKey == null)
                {
                    Console.WriteLine("没有Ip配置");
                }
                else
                {
                    string[] ipaddresses = (string[])networkKey.GetValue("IPAddresss");
                    string[] defaultGateways = (string[])networkKey.GetValue("DefaultGateways");
                    string[] subnetmasks = (string[])networkKey.GetValue("SubnetMask");
                    foreach (string ipaddress in ipaddresses)
                    {
                        Console.WriteLine("IP地址:{0}", ipaddress);
                    }
                    foreach (string subnetmask in subnetmasks)
                    {
                        Console.WriteLine("子网掩码:{0}", subnetmask);
                    }
                    foreach (string defaultGateway in defaultGateways)
                    {
                        Console.WriteLine("网关:{0}", defaultGateway);
                    }
                    networkKey.Close();
                }
            }
            start.Close();
        }
    }
}

相关文章:

  • 2021-07-07
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-05-27
  • 2021-04-10
猜你喜欢
  • 2021-07-15
  • 2021-11-16
  • 2021-09-14
  • 2022-12-23
  • 2022-01-29
  • 2022-12-23
相关资源
相似解决方案