What you don't seem to understand is that addresslist is in fact a list.
The return value contains multiple values where some addresses are ipv4 and some are ipv6. If you are relying on the fact that the one of length-2 is ipv4 then you are doing poor style of programming.
What you should do instead is iterate through all addresses and then inspect the addressfamily.
http://msdn.microsoft.com/en-us/library/system.net.ipaddress_members(v=vs.80).aspx[
^]
als see
http://msdn.microsoft.com/en-us/library/system.net.ipaddress.addressfamily(v=vs.80).aspx[
^]
In your code you are iterating through all addresses and the last will be shown on the label. Since you want only ipv4 addresses the first will do so something like this is better
for(int i=0; i< hostInfo.AddressList.Length; i++)
{
if (addr[i].AddressFamily.ToString() == ProtocolFamily.InterNetworkV6.ToString()){
try
{
ipLabel.Text= Convert.ToString(addr[i]) + "\r\n";
}
catch
{
ipLabel.Text += "IP Address | " + "\r\n";
}
break;
}
}