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

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

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

4条回答
  •  鱼传尺愫
    2020-12-01 19:24

    My desired answer was

    string ipAddress = "";
    if (Dns.GetHostAddresses(Dns.GetHostName()).Length > 0)
    {
         ipAddress = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
    }
    

提交回复
热议问题