using System.Net;

        /// <summary>
        
/// 得到用戶電腦信息
        
/// </summary>
        public void GetUserInfo()
        {
            
string sIP = "";

            
//得到計算機名 方法1
            string MachineName = System.Environment.MachineName;
            
//得到計算機名 方法2
            string strHostName = Dns.GetHostName();

            IPAddress[] addr;

            
//得到IP 方法1
            
//addr = Dns.GetHostAddresses(strHostName);
            
//得到IP 方法2
            addr = Dns.GetHostAddresses("127.0.0.1");
            
//得到IP 方法3
            
//addr = Dns.GetHostAddresses("localhost");

            
//得到IP 方法4
            
//IPHostEntry ihIP = Dns.GetHostEntry(strHostName);
            
//addr = ihIP.AddressList;

            
//得到IP 方法5 此句顯示老式語句警告
            addr = Dns.GetHostByName(Dns.GetHostName()).AddressList;

            
if (addr.Length<=1)
            {
                sIP 
= addr[0].ToString();
            }
            
else
            {
                
for (int iCount = 0; iCount < addr.Length; iCount++)
                {
                    sIP 
+= "IP" + (iCount + 1).ToString() + ":" + addr[iCount].ToString() + " ";
                }
            }           
        }


相关文章:

  • 2021-08-20
  • 2021-11-09
  • 2021-10-25
  • 2021-10-09
  • 2022-01-13
  • 2021-09-15
  • 2021-07-26
  • 2022-02-22
猜你喜欢
  • 2021-07-13
  • 2021-04-01
  • 2021-06-06
  • 2021-11-23
  • 2021-08-08
  • 2021-11-23
  • 2021-06-22
相关资源
相似解决方案