Gali Gali - 1 month ago 5
C# Question

how to get the IP of my device and the server IP (windows-CE)

how do i get my IP and the server's IP in windows-CE (using C#)?


Your question is vague. I don't know which adapter or type of address you want, so I assume you want the IPv4 address of the first local adapter. That would look something like this:

var ip = (from a in Dns.GetHostEntry(Dns.GetHostName()).AddressList
     where a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
      select a).First().ToString();

Getting the IP address of a given server would require that you know it's hostname and then you'd do a lookup (i.e. Dns.GetHostEntry) on that name. It would look a lot like the code above, except you'd use the server host name instead of the Dns.GetHostName() call.