0

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

sarsnake
  • 26,667
  • 58
  • 180
  • 286

1 Answers1

0

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

S P
  • 4,615
  • 2
  • 18
  • 31