如何在 C++ 中找到映射网络驱动器的 IP 地址?
我有一个可用于默认输入数据目录的可能路径列表(X:\Data; Y:\Data; Z:\Data)。所有可能的路径都映射到网络驱动器。我可以使用 GetDriveType(pathStr) == DRIVE_REMOTE 来检查这一点。为了确定最佳路径,我通过仅选择存在的路径来缩小列表范围。有时列表中会留下多个路径,因此为了确定此时最好的一条路径,我想找到驱动器映射到的服务器的 IP 地址,这样我可以将其与我自己的 IP 地址进行比较。例如,如果我将 X:\
映射到 \\RemoteComputer\ShareName
,我如何从字符串 X:\Data
中找到RemoteComputer
的名称或 IP 地址? (我已经能够从计算机名称中找到IP地址)。
I have a list of possible paths to use for a default input data directory (X:\Data; Y:\Data; Z:\Data). All of the possible paths are mapped network drives. I can check this using GetDriveType(pathStr) == DRIVE_REMOTE
. To determine the best one, I have narrowed down the list by selecting only paths that exist. Sometimes there will be more than one path left in the list, so to determine the best one at that point, I want to find the IP address of the server that the drive is mapped to, so I can compare it to my own IP address. For instance, if I have X:\
mapped to \\RemoteComputer\ShareName
, how can I find out from the string X:\Data
either the name or IP address of RemoteComputer
? (I already have the ability to find the IP address from a computer name).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WNetGetUniversalName
是一种可能性。WNetGetUniversalName
is one possibility.请记住,并非所有(但绝大多数)UNC 路径都以计算机名称开头。有些像 WebDav 是 FQDN,有些像 TS remoting(即 \tsclient\c)根本不是机器,只是 RDBSS 识别的令牌。
Keep in mind, that not all (but the vast majority) of UNC paths start with a computer name. Some like WebDav, are a FQDN - others like TS remoting (i.e. \tsclient\c) aren't a machine at all, just a token that RDBSS recognizes.