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

為{幸葍}努か 提交于 2019-11-29 07:32:44

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

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.

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