- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在Linux中,我默认通过设置java.net.preferIPv4Stack=true来禁用IPv6支持,仅在应用程序中支持IPv4。
但是,我现在想使用 InetAddress.isReachable(timeout) 访问外部 IPv6 IP,但它完全失败,并且仅当我设置 java.net.preferIPv4Stack=false 时才有效。
是否有任何方法可以访问 IPv6 IP,但仍保持 java.net.preferIPv4Stack=true?
谢谢
最佳答案
不,这是不可能的,因为您设置的选项 explicitly disables communication with IPv6 only hosts:
java.net.preferIPv4Stack (default: false)
If IPv6 is available on the operating system the underlying native socket will be, by default, an IPv6 socket which lets applications connect to, and accept connections from, both IPv4 and IPv6 hosts. However, in the case an application would rather use IPv4 only sockets, then this property can be set to true. The implication is that it will not be possible for the application to communicate with IPv6 only hosts.
如果您想确保 IPv4 地址优先于 IPv6 地址,但仍然有 IPv6 可用,那么您很幸运 - 这是默认行为! (如果您出于任何原因想要将其更改为首选 IPv6 地址,可以设置 java.net.preferIPv6Addresses=true。)
关于java - 当 java.net.preferIPv4Stack=true 时,无法对 IPv6 使用 InetAddress.isReachable(timeout),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50188394/
我使用的是 Windows 8 和 JDK 1.7。我的IP地址是192.168.1.108,当我运行时: System.out.println(InetAddress.getLocalHost().
我正在尝试使用“isReachable”方法检查某个主机是否可达。 line 113: oaiBaseURL = "http://www.cnn.com";//////////////////////
我向所有 Java 专家提出以下问题。 我正在尝试想出一种可靠的方法来创建 localHost InetAddress 对象,作为 InetAddress.getLocalHost() 的后备方法。
我使用以下代码来检查所提供的 IP 在 java 中是否可访问。 public String isNetworkReachable(){ int timeout = 2000;
我想要 InetAddress 的实例,但不想像强制该类的每个工厂方法那样将其放入 try-catch 中: InetAddress addr = InetAddress.getByAddress(i
我解析各种包含网络信息的数据源。 我一直在使用java.net.InetAddress来表示和解析主机。用 IP 初始化它工作正常。 我现在必须解析一个新的来源。它包含主机名而不是 IP。 InetA
由于某种原因,我似乎无法初始化 InetAddress 对象,我查看了文档,它与我的使用方式完全相同。 InetAddress firstMachineAddress = InetAddress.g
这个问题已经有答案了: Creating InetAddress object in Java (7 个回答) 已关闭 8 年前。 我知道如何使用它的静态方法为受试类创建一个实例,但有一些我无法理解的
我有下面的代码,在继续之前我用它来获取服务器的完整规范主机名。这将在我的服务器上返回一个值(特别是不同的域)。命令行上的 nslookup 返回正确的值。 我试图了解 java.inet 在内部到底做
我是 Java 的新手,但不是编程人员,我遇到了这个问题: InetAddress localAddress = InetAddress.getLocalHost(); 它让我很反感。我们将 loca
谁能解释一下 InetAddress 之间有什么区别吗?和 InetSocketAddress java中的类,如果有差异,请解释相同。我用谷歌搜索了它,但找不到任何解释。 最佳答案 InetAddr
我正在尝试了解 InetAddress.getLocalHost() 的工作原理。 Javadoc表示它从系统中检索主机名,然后将其解析为 InetAddress。 “解析为 InetAdess”到底
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
这个问题已经有答案了: Slash before InetAddress.getByName(host) (2 个回答) 已关闭 9 年前。 我想我的问题对于这里的人来说很容易回答吗?问题是,当我执行
我试图每 10 秒循环 ping 200 个 IP。因此,该循环每 10 秒执行一次。我使用此代码来 ping IP for (i = 0; i <= 200; i++ ) { ProcessB
在我的 Java 应用程序中,我需要一次获取多个连接的 ping,我尝试过为每个连接使用一个线程并测量响应时间,但它们似乎并不都是正确的。 是否有线程安全的方法来测量连接的 ping/响应时间?我目前
我有这个代码: import java.net.InetAddress; import java.net.UnknownHostException; public class NsLook
我在尝试模拟 InetAddress 中的静态方法时遇到了奇怪的问题。我能够成功地为许多其他类模拟静态方法并且一切正常,但 InetAddress 显示不同的行为。我正在使用 JUnit 4.x、Mo
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我正在使用 Java InetAddress 来查找当前的互联网连接是否可以通过 DNS 解析地址。但是,如果我输入一个随机地址(互联网上绝对不存在的地址),我仍然会得到一个 IP,谁能解释为什么会出
我是一名优秀的程序员,十分优秀!