IP address that the handheld currently has

  • Thread starter Thread starter Harsh Trivedi
  • Start date Start date
H

Harsh Trivedi

I wanted to obtain the IP address that the hand held currently has,
my device is Windows Mobile 6.0. Can anyone please help me how to do
it programatically? [c#]


Thank you
 
There is no *the* address. The device might have several, WiFi, GPRS, and
ActiveSync, for example. Look at the OpenNETCF Smart Device Framework,
www.opennetcf.com. It has classes in there to get a list of network
adapters and the IP address for each one.

Paul T.
 
Thanks for the reply. I write the following code, and it gives me all
IP address those are configure in the device:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using System.Net;

IPHostEntry entry = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress add in entry.AddressList)
MessageBox.Show("IP Address: " + add.ToString());
 
I've never attempted to do it that way. It might or might not work. If you
can't find any cases where it gives you too many entries (localhost), or too
few, I don't see any basic problem with it.

Paul T.
 
Like most things, it depends on what you're doing. If the device is just
configured for GPRS/3G etc and you never use any other type of connection
then doing somthing like this will work just fine:

string host = Dns.GetHostName();
IPHostEntry ipHost = Dns.GetHostEntry(host);
string myip = ipHost.AddressList[0].ToString();

For other more complex scenarios, you might have 2, ie WiFi and GSM. But if
connecting via a crade all connections will be dropped so you'll have just
the one.
 
Thanks Simon....

We are using GRPS, WIFI and Bluetooth. In the field, GPRS, in the
complex Wifi, and in the office, bluetooth. It may possible at a time
that, we have GPRS and Bluetooth at a time. Why this 3 things, is not
in my hand :) , we have to follow it.

How to handle this scenario?
 
Then you'll need to identify the network adapter for each. Take Pauls advice
and take a look at the OpenNETCF SDF. Otherwise you'll have to get low-level
and start working at the Win32 API level as there is nothing in the Compact
Framework that will assist you with this problem.
 
Back
Top