Domain Name Interpretation Utility for java

I am in need of using the java utility to get the fully qualified host name and create the domain name .

In the simple case, this means turning host.company.com into company.com , but this is more complicated with host.subdomain.company.com , for example, or host.company.co.uk , where the value of the "domain name" becomes a little fuzzy , Throw complications with the definition of SLD and ccSLD , and it becomes erratic.

So my question is whether there is a third-party library that understands these things and can give me reasonable interpretations.

+1
source share
3 answers

Mozilla regularly maintains the rules that it uses in its browser for the security of cookies in a format that can be analyzed and used by others:

http://publicsuffix.org/

A Google search may have Java libraries that can parse a list, but I don’t know the quality of any of them.

+3
source

I do not think that such a thing exists, since it is an administrative rather than a technical problem, and it is very multilateral.

If you're done on your own, this Mozilla wiki page looks like a good starting point, with lots of links. Seems like a serious headache. Just look at the rules for Japan . Uch.

+3
source

Not sure if for the same purpose I am doing something similar in my code. When I set cookies, I want to set the domain as close to the top as possible, so I need to find the domain at a level lower than the open suffix. For example, the highest domain you can set for the cookie for host.div.example.com is .example.com . For host.div.example.co.jp there is .example.co.jp .

Unfortunately, the code is not in the public domain. It is very easy to do. I mainly use the following 2 classes from Apache HttpClient 4,

 org.apache.http.impl.cookie.PublicSuffixFilter org.apache.http.impl.cookie.PublicSuffixListParser 

I forgot the exact reason, but we had to do some minor tricks. You simply move the domain from top to bottom, the first valid cookie domain is what you need.

You need to download the public suffix list and include it in your JAR,

http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/src/effective_tld_names.dat?raw=1

+1
source

Source: https://habr.com/ru/post/1299452/


All Articles