How to get the IP address of a machine in C#

前端 未结 4 461
予麋鹿
予麋鹿 2020-12-01 18:35

How do I get the IP address of a machine in C#?

4条回答
  •  感情败类
    2020-12-01 19:14

     IPHostEntry ip = DNS.GetHostByName (strHostName);
     IPAddress [] IPaddr = ip.AddressList;
    
     for (int i = 0; i < IPaddr.Length; i++)
     {
      Console.WriteLine ("IP Address {0}: {1} ", i, IPaddr[i].ToString ());
     }
    

提交回复
热议问题