views:

3308

answers:

2

I have a .Net Compact app running on Windows Mobile, and I want to be able to connect to a webservice running on the 'host' machine (i.e. the desktop the PDA is plugged into) when connected via ActiveSync, but I don't know the ip address of the host. How can I find the ip of the desktop PC progromatically on the PDA?

+2  A: 

Getting the address is no different than when you're connected to any other network adapter (typically ActiveSync is running over RNDIS nowadays).

Dns.GetHostEntry(Dns.GetHostName()).AddressList[0];

That said, ActiveSync always creates a local network, so the device is always going to get 192.168.55.101 (and 192.168.55.100 for the host PC). In theory it could be something different, but in the decade I've been working with CE, I've never seen it give any other address (except under Vista's WMDC, which tends to use a different, but quite predictable, addressing scheme).

EDIT: It appears that you're not trying to get your own IP, but that of the connected PC. ActiveSync is not a full-blown network connection. It filters some packet types and you don't get name resolution, so you can't get the PC's IP address from the device code by doing a Dns.Resolve on the PC name. You have to provide the IP directly to the device app.

ctacke
Using Dns.GetHostEntry(Dns.GetHostName()).AddressList[0] seems to give the ip of the device: 169.254.2.1 in my case (connected with Vista x64 Sync Center). ipconfig on the desktop shows Windows Mobile Remote Adapter using 169.254.2.2, which is what I want to find out for connecting to the webservice
Wilka
The WMDC IP address (2.2) is the address of the PC RNDIS adapter. The Device address (2.1) is the address of the device RNDIS adapter, so both of those are expected.
ctacke
Thanks, I was hoping I would be able to work out the IP or count on a fixed ip - but it looks like I'm going to have to find another way of telling the device which webservice to connect to.
Wilka
+3  A: 

I've found a KB article How To Retrieve the IP Address of the Remote PPP Peer, which uses the host "PPP_Peer". So I tried:

Dns.GetHostEntry("PPP_Peer").AddressList[0]

And that does give me what I'm looking for (169.254.2.2 on the PC I'm using at the moment).

Wilka