I use an java API to extract the second domain name based on the given URLs.
https://github.com/whois-server-list/public-suffix-list
It based on the PUBLIC SUFFIX LIST
of Mozilla.
Given codes below:
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);
}
I got the following output:
apple.com
siriusxm.com
spotify.com
apple.com
google.com
apple.com
apple.com
google.com
amazonaws.com
null
It works well for most domains, but for the s3.amazonaws.com
, it returns null. However for a similar one: s4.amazonaws.com
, it give the right result. What's the issue?
s3.amazonaws.com is included in the public suffix list and therefore considered as not registrable.
PublicSuffixList.getRegistrableDomain()
returnsnull
in this case: