How do I determine the local host’s IPv4 addresses?

后端 未结 11 1411
[愿得一人]
[愿得一人] 2020-12-05 13:23

How do I get only Internet Protocol version 4 addresses from Dns.GetHostAddresses()? I have the code below, and it gives me IPv4 and IPv6 addresses. I have to m

11条回答
  •  感动是毒
    2020-12-05 14:12

    Here is a code to find the first connected IPv4 by using for loop :

            IPAddress ipAddress = null;
            IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());           
    
            for (int i=0 ; i

提交回复
热议问题