windows 如何在 C++ 中找到映射网络驱动器的 IP 地址?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3531700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I find the IP address of a mapped network drive in C++?
提问by Ben
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).
我有一个用于默认输入数据目录(X:\Data; Y:\Data; Z:\Data)的可能路径列表。所有可能的路径都映射到网络驱动器。我可以使用GetDriveType(pathStr) == DRIVE_REMOTE
. 为了确定最佳路径,我通过仅选择存在的路径来缩小列表的范围。有时列表中会剩下不止一条路径,所以为了确定那个点的最佳路径,我想找到驱动器映射到的服务器的IP地址,这样我就可以将它与我自己的IP地址进行比较. 例如,如果我已X:\
映射到\\RemoteComputer\ShareName
,我如何从字符串中找出X:\Data
的名称或 IP 地址RemoteComputer
?(我已经能够从计算机名称中找到 IP 地址)。
回答by Jerry Coffin
WNetGetUniversalName
is one possibility.
WNetGetUniversalName
是一种可能性。
回答by Ana Betts
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.
请记住,并非所有(但绝大多数)UNC 路径都以计算机名称开头。有些像 WebDav,是一个 FQDN - 其他像 TS 远程处理(即 \tsclient\c)根本不是一台机器,只是 RDBSS 识别的令牌。