Java api public-suffix-list返回空域

时间:2014-11-14 14:52:34

标签: java dns tld public-suffix-list

我使用java API根据给定的URL提取第二个域名。

https://github.com/whois-server-list/public-suffix-list

它基于Mozilla的PUBLIC SUFFIX LIST

考虑以下代码:

PublicSuffixListFactory factory = new PublicSuffixListFactory();
    PublicSuffixList suffixList = factory.build();
    String[] domainArray = new String[10];
    domainArray[0] = "swcdn.apple.com";
    domainArray[1] = "production-pdt.siriusxm.com";
    domainArray[2] = "audio2.spotify.com";
    domainArray[3] = "a1935.phobos.apple.com";
    domainArray[4] = "r13---sn-ab5l6n7r.c.pack.google.com";
    domainArray[5] = "a132.phobos.apple.com";
    domainArray[6] = "a1736.phobos.apple.com";
    domainArray[7] = "r17---sn-vgqs7n7l.c.android.clients.google.com";
    domainArray[8] = "s4.amazonaws.com";
    domainArray[9] = "s3.amazonaws.com";

    for(String string : domainArray){
        String domain = suffixList.getRegistrableDomain(string);
        System.out.println(domain);
    }

我得到了以下输出:

apple.com
siriusxm.com
spotify.com
apple.com
google.com
apple.com
apple.com
google.com
amazonaws.com
null

适用于大多数域,但对于s3.amazonaws.com,它返回null。但是对于类似的:s4.amazonaws.com,它会给出正确的结果。问题是什么?

1 个答案:

答案 0 :(得分:2)

s3.amazonaws.com 包含在public suffix list中,因此被视为无法注册。在这种情况下,PublicSuffixList.getRegistrableDomain()会返回null

  

返回:       可注册域名,如果域名不可注册,则为null