gpt4 book ai didi

java - 如何在 Java 中通过计算机全名 ping 机器

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:51:52 26 4
gpt4 key购买 nike

在问这个问题之前,我在这里搜索了一下。

InetAddress.getByName("SOMECONSTANTCOMPUTERNAME.xxx.CORP.xxx.COM").isReachable(10000)

这总是返回 false 或 UnknownHostException 但通过使用 cmd 和编写

ping SOMECONSTANTCOMPUTERNAME.xxx.CORP.xxx.COM

我正在获取 ping 状态。

如果我没有做适当的研究,最后道歉。

问候,ICR

最佳答案

您可能正在尝试获取 IPv6 地址的 IP 地址,并且为全局 IPv6 地址指定了 scope_id。由于 API 仅在此处提到的两种情况下抛出 UnknownHostException:

getByName

public static InetAddress getByName(String host) throws UnknownHostException Determines the IP address of a host, given the host's name. The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address. If a literal IP address is supplied, only the validity of the address format is checked.

For host specified in literal IPv6 address, either the form defined in RFC 2732 or the literal IPv6 address format defined in RFC 2373 is accepted. IPv6 scoped addresses are also supported. See here for a description of IPv6 scoped addresses.

If the host is null then an InetAddress representing an address of the loopback interface is returned. See RFC 3330 section 2 and RFC 2373 section 2.5.3.

Parameters: host - the specified host, or null.

Returns: an IP address for the given host name.

Throws: UnknownHostException - if no IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.

在此处了解有关 IPv6 范围地址的更多信息:

http://docs.oracle.com/javase/6/docs/api/java/net/Inet6Address.html#scoped

关于java - 如何在 Java 中通过计算机全名 ping 机器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17361317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com