- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在问这个问题之前,我在这里搜索了一下。
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/
我是一名优秀的程序员,十分优秀!