如果我在 java 或 cmd 提示符中有该共享驱动器的路径,如何查找共享驱动器 IP 地址

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12789033/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 10:13:55  来源:igfitidea点击:

how to find shared drive IP address if i have a path for that shared drive in java or cmd prompt

javapathcmdwindows-share

提问by mdp

I have a path windows network shared drive like this .

我有一个像这样的路径 Windows 网络共享驱动器。

String url="//sample/data/Documents/network/test/";

How can i find the Ip address of the that drive using this path using a java program or cmd prompt?

如何使用 java 程序或 cmd 提示符使用此路径找到该驱动器的 IP 地址?

回答by Alfabravo

Via cmd prompt, you can get the IP pinging to 'sample' (following your example in the question) as the console must resolve hostname to IP address.

通过 cmd 提示符,您可以将 IP ping 发送到“示例”(按照问题中的示例),因为控制台必须将主机名解析为 IP 地址。

Via java, perhaps InetAddress.getByName('sample')could work.

通过java,也许InetAddress.getByName('sample')可以工作。

All this assuming the shares are not going over NetBIOS and all the old stuff. That doesn't work over IP as the comment says.

所有这些都假设共享不超过 NetBIOS 和所有旧东西。正如评论所说,这不适用于 IP。

回答by AlexR

Although @Greg is right I think in most cases you can extract the host name from the URL and then use InetAddress.getByName(), i.e. something like the following

虽然@Greg 是对的,但我认为在大多数情况下,您可以从 URL 中提取主机名,然后使用InetAddress.getByName(),即类似于以下内容

String host = url.substring(2).replaceFirst("/.*", "");
InetAddress.getByName(host);

回答by wolf97084

Open windows cmd prompt, type in nslookup \network_share_drive_name it will come back with name and address of your gateway server and the network share drive. Here you can type nslookup \sample

打开 Windows cmd 提示符,输入 nslookup \network_share_drive_name 它将返回您的网关服务器和网络共享驱动器的名称和地址。在这里你可以输入 nslookup \sample