In C #:
IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName()); for (int i = 0; i < IPHost.AddressList.Length; i++) { textBox1.AppendText("My IP address is: " + IPHost.AddressList[i].ToString() + "\r\n"); }
In this code, the IPHostEntry variable contains all the IP addresses of the computer. Now, as far as I know, Windows Vista returns several IP addresses in hexadecimal, some in decimal notation, etc.
The problem is that the desired decimal notation changes its location in the IPHostEntry variable: it originally occurred in the last place and therefore could be accessed with the code:
string ipText = IPHost.AddressList[IPHost.AddressList.Length - 1].ToString();
However, after changing the IP address of the computer, it now appears in the 2nd last place and therefore should be accessible using the code:
string ipText = IPHost.AddressList[IPHost.AddressList.Length - 2].ToString();
Is there any code that retrieves the IP addresses in decimal notation regardless of its location in the IPHostEntry variable ??
source share