IP address that the handheld currently has

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
 
P

Paul G. Tobey [eMVP]

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.
 
H

Harsh Trivedi

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());
 
P

Paul G. Tobey [eMVP]

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.
 
S

Simon Hart [MVP]

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.
 
H

Harsh Trivedi

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?
 
S

Simon Hart [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top