.Net IPAddress IPv4

.net, c#, ip-address, vb.net

Solution

Instead of unconditionally taking the first element of the AddressList, you could take the first IPv4 address:

var address = Dns.GetHostEntry(strHostname)
                 .AddressList
                 .First(ip => ip.AddressFamily == AddressFamily.InterNetwork);

Problem

I have the following code: ``` Dim ipAdd As IPAddress = Dns.GetHostEntry(strHostname).AddressList(0) Dim strIP As String = ipAdd.ToString() ``` When I convert to String instead of an IPv4 address like 192.168.1.0 or similar I get the IPv6 version: fd80::5dbe:5d89:e51b:d313 address. Is there a way I can return the IPv4 address from IPAddress type? Thanks

Original source