Advertisement

掌握C#基础用于获取网络接口的IP与MAC

阅读量:

获取IP

复制代码
         string hostInfo = Dns.GetHostName();

    
  
    
         //IP地址
    
         //System.Net.IPAddress[] addressList = Dns.GetHostByName(hostInfo).AddressList;这个过时
    
         System.Net.IPAddress[] addressList = Dns.GetHostEntry(hostInfo).AddressList;
    
         ip = addressList[0].ToString();
    
    
    
    

二:适用于多网卡配置的情况

复制代码
        foreach (NetworkInterface netInt in NetworkInterface.GetAllNetworkInterfaces())

    
        {
    
             IPInterfaceProperties property = netInt.GetIPProperties();
    
             foreach (UnicastIPAddressInformation

全部评论 (0)

还没有任何评论哟~