Friday, December 25, 2009

How to get the IP Address of a device in .NETCF

Here's something I see asked every now and then in the community forums. The solution is a one liner that looks like this:

IPAddress[] addresses = Dns.GetHostEntry(Dns.GetHostName()).AddressList;

The code above retrieves the IP addresses for each connected network adapter of the device. The Dns and IPAddress classes belong to the System.Net namespace.

1 comment:

stig atle said...

thank you, very useful!