Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ip address of host pc from windows mobile when connected via ActiveSync

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?

like image 944
Wilka Avatar asked Jan 20 '09 16:01

Wilka


2 Answers

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

like image 137
Wilka Avatar answered Oct 12 '22 00:10

Wilka


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.

like image 40
ctacke Avatar answered Oct 12 '22 00:10

ctacke