zoukankan      html  css  js  c++  java
  • C#获取本地计算机名IP,Mac地址

                string s="",mac="";
                //
                //name
                //
                string hostInfo = Dns.GetHostName();            

                //
                //IP
                System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;  
                for (int i = 0; i < addressList.Length; i ++)
                {
                    s += addressList[i].ToString();
                }
                //
                //mac
                //


                ManagementClass mc;
                mc=new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc=mc.GetInstances();
                foreach(ManagementObject mo in moc)
                {
                    if(mo["IPEnabled"].ToString()=="True")
                        mac=mo["MacAddress"].ToString();                    
                }


                txtName.Text=hostInfo;
                txtIp.Text=s;
                txtMac.Text=mac;


                button1.Enabled=false;
                button2.Focus();
  • 相关阅读:
    [ python ] 函数的参数
    [ python ] 文件读写操作
    [ python ] 集合的使用
    [ python ] 购物系统
    [ python ] 字符编码
    [ python ] 字典的使用
    [ python ] 列表和元组
    [ python ] 字符串的操作及作业题
    [ python ] 格式化输出、字符集、and/or/not 逻辑判断
    [ python ] 变量及基础的数据类型
  • 原文地址:https://www.cnblogs.com/asyuras/p/244421.html
Copyright © 2011-2022 走看看