【发布时间】:2011-11-04 06:37:01
【问题描述】:
我有两台计算机插入我知道支持 IPv6 的网络的同一路由器。我们称它们为“PC-A”和“PC-B”
我希望“PC-A”找出“PC-B”的 IPv6 地址,反之亦然
我做的第一件事是
setSystem.setProperty("java.net.preferIPv6Addresses", "true");
如果我说
InetAddress IPAddress = InetAddress.getLocalHost();
我可以得到自己的地址,该地址将采用 IpV6 格式
但是,以下两个语句都没有给出“PC-B”的 IPv6 地址:
Inet6Address IPAddress6 = (Inet6Address)InetAddress.getByName("PC-B");
InetAddress IPAddress = InetAddress.getByName("PC-B");
我也尝试过导入
import com.lavantech.net.dns.SimpleDNSLookup;
import com.lavantech.net.dns.DNSLookup
我使用的第一个:
SimpleDNSLookup d = new SimpleDNSLookup();
System.out.println(d.getInet6Address("PC-B"));
第二个为:
DNSLookup dnsLookup = new DNSLookup("PC-B", DNSLookup.QTYPE_AAAA, DNSLookup.QCLASS_IN, 3000, null);
// Get all Address Records.
ResourceRecord[] ansRecords = dnsLookup.getAAAARecords();
System.out.println(ansRecords[0]);
这些都不行。
我也试过用下面的
import org.xbill.DNS.*;
int type = Type.AAAA;
Name name = Name.fromString("PC-B");
Lookup lookup = new Lookup(name, type);
lookup.run();
int result = lookup.getResult();
Record[] answers = lookup.getAnswers();
System.out.println(answers[0]);
// (where, for brevity, i am skipping the parts where I check whether result == Lookup.SUCCESSFUL
- 请注意,如果我用“PC-B”代替“ipv6.google.com”,我会得到所有想要的结果!
- 还请注意,如果我在上述方法中的适用情况下仅使用 InetAddress 和 Type_A,我的程序将毫无问题地返回“PC-B”的 IPv4 地址。
我错过了什么? 非常感谢任何帮助!
【问题讨论】:
-
我不相信你能在你的网络上对本地计算机进行 DNS 查找,除非你有一个运行着记录 PC-A 和 PC-B 的 DNS 服务器