tags:

views:

27

answers:

1

I use .net 3.5/c#

I need to get server's IP, I was using this code:

string strHostName = Dns.GetHostName();
IPHostEntry hostInfo = Dns.GetHostEntry(strHostName);
string serverIpParam = hostInfo.AddressList[0].ToString();


return serverIpParam;

However, after a switch to Windows 2008 server, my IP has letter format instead of usual format (digits). MSDN doesn't shed any light on this. Any ideas what I should change to get the server IP? Thanks

+1  A: 

Did you looked at all the addresses that are returned by hostInfo.AddressList?

When I execute the following in LinqPad:

  string strHostName = System.Net.Dns.GetHostName(); 
  System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostEntry(strHostName); 
  for(int index=0; index < hostInfo.AddressList.Length; index++) {
      Console.WriteLine(hostInfo.AddressList[index]);

  }

IT will return me a whole list of network interfaces. In your case, I think the first entry points to an IPV6 address

Sander Pham
it just has that one address in a format of letters, not digits....
gnomixa