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();
  • 相关阅读:
    SDUT2482二叉排序树
    POJ 3278Catch That Cow
    SDUT2140图结构练习——判断给定图是否存在合法拓扑序列
    SDUT2142数据结构实验之图论二:基于邻接表的广度优先搜索遍历
    SDUT2141数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历
    SDUT1466双向队列
    搜索
    搜索
    贪心算法
    贪心算法
  • 原文地址:https://www.cnblogs.com/asyuras/p/244421.html
Copyright © 2011-2022 走看看