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

一曲冷凌霜 提交于 2019-11-28 01:08:08

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/461957/get-ip-address-of-host-pc-from-windows-mobile-when-connected-via-activesync

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!