zoukankan      html  css  js  c++  java
  • c#获取网关和Ip

    方法很多,有简有烦,这里选择了个麻烦的。

    主要代码:

      private void getxx(){
    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 serviceNames = start.OpenSubKey(networkcardKey);
     if (serviceNames == null)
    {
    MessageBox.Show("Bad registry key");
    return;
    }
    string[] networkCards = serviceNames.GetSubKeyNames();
    serviceNames.Close();
    foreach(string keyName in networkCards)
    {
    networkcardKeyName = networkcardKey + "\\" + keyName;
    cardServiceName = start.OpenSubKey(networkcardKeyName);
    if (cardServiceName == null)
    {
        MessageBox.Show(networkcardKeyName);
    return;
    }
    deviceServiceName =(string)cardServiceName.GetValue("ServiceName");
    deviceName = (string)cardServiceName.GetValue("Description");
        MessageBox.Show( deviceName);
    serviceName = serviceKey + deviceServiceName + "\\Parameters\\Tcpip";
    networkKey = start.OpenSubKey(serviceName);
    if (networkKey == null)
    {

    。。。。。。
    }
    else
    {
    string[] ipaddresses =(string[])networkKey.GetValue("IPAddress");
    string[] defaultGateways =(string[])networkKey.GetValue("DefaultGateway");
    string[] subnetmasks =(string[])networkKey.GetValue("SubnetMask");
    foreach(string ipaddress in ipaddresses)
    {
        MessageBox.Show( ipaddress);
         }
    foreach(string subnetmask in subnetmasks)

    。。。。。。}
    foreach(string defaultGateway in defaultGateways)
    {
        MessageBox.Show(defaultGateway);
    }
    networkKey.Close();
    }
    }
    start.Close(); 
            }

  • 相关阅读:
    RabbitMQ一:消息队列的认识
    RabbitMQ二:AMQP协议
    SVN中如何去除版本控制器
    Asp.net:MVC认识
    时间连接查询展示
    C#string类型总结
    JavaScript01天学习笔记分享
    UML中的类图及类图之间的关系
    23 种设计模式的分类和功能
    WCF入门
  • 原文地址:https://www.cnblogs.com/jinyuttt/p/1805933.html
Copyright © 2011-2022 走看看