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 a number of IP addresses some in hexadecimal, some in decimal notation and so on.
The problem is that the decimal notation which is desired changes its location in the IPHostEntry
variable: It initially was occuring in the last location and so 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 location and so needs to be accessed using the code:
string ipText = IPHost.AddressList[IPHost.AddressList.Length - 2].ToString();
Is there any code that retrieves the IP addresses in decimal notation irrespective of its location in the IPHostEntry
variable??