Windows phone has a native API for dealing with underlying network stack. Long time ago daenet has implemented the tool called DHOST for Windows Mobile, which shows information about all adapters on device.
I was a pretty disappointed as I heard that Windows Phone will not have public API at the release time. So I decided to it by using of undocumented API.
This API is implemented in assembly called Iphlpapi. This assembly with the name which breaks all MS-guidelines supports following networks:
Any
Broadcast;
IPv6Any
IPv6Loopback
IPv6None
Loopback
None
Here is the peace of code which enumerates all adapters on device:
IList<Iphlpapi.AdapterInfo> addresses = NativeAccess.Net.Iphlpapi.getIPAddresses();
foreach (var addr in addresses) { msg += String.Format("{0}\r\n{1}\r\n{2}\r\n\r\n", addr.FriendlyName, addr.Address, addr.Description); } MessageBox.Show(msg); |
Note that this code will not work on Emulator, because emulator doe not have all required COM Dll-s. This API can also do meny other things.
Here is an example which shows how to get the HostName.
var hostName = Dns.GetHostName();
It is interesting, that my host name is “SmartPhone”.
We implemented finally the tool called DHost For Windows Phone, which will be available soon. Note that the first version will not be published in the public store, because it will probably not pass certification process
Here is the screenshot of the V1:
As you see my lab-device has 5 adapters
Posted
Jan 30 2011, 12:49 AM
by
Damir Dobric