javawhois

How do I findout domain expiry date of a .org and .in website in java


I'm using WhoisClient (org.apache.commons.net.whois.WhoisClient) to retrieve my website domain expiry date. It is working for the domain with .com extension. When I try to check the expiry date for one of my .org domain the result says No match for domain.org. How do I find out the expiry date of a .org and .in extension domain?

I'm using the following code for getting the expiry date of the domain

String domainName =  mydomain.replaceFirst("^(http[s]?://www\\.|http[s]?://|www\\.)","");
WhoisClient whois = new WhoisClient();
whois.connect(WhoisClient.DEFAULT_HOST);
String whoisData1 = whois.query("=" + domainName);
whois.disconnect();

Solution

  • Do not bother with the whois protocol.

    Now (since August 26th, 2019) per ICANN requirements, all gTLDs need to have an RDAP server. RDAP is like the successor of whois: kind of the same content exchanged but this time on top of HTTPS with some fixed JSON format. Hence, trivial to parse.

    The expiry date will be in the "events" array with an action called "expiration".

    You can go to https://data.iana.org/rdap/dns.json to find out the .ORG RDAP server, it is at URL https://rdap.publicinterestregistry.net/rdap/org/

    You need to learn a little more about RDAP to understand how to use it (structure of the query and the reply), you can find some introduction at https://about.rdap.org/

    But in short your case, this emulates what you need to do:

    $ wget -qO - https://rdap.publicinterestregistry.net/rdap/org/domain/slashdot.org | jq '.events[] | select(.eventAction | contains("expiration")) | .eventDate'
    "2019-10-04T04:00:00.000Z"
    

    PS1: if you get no match from a whois query normally it really means that the domain does not exist; it could also be because of rate limiting

    PS2: .IN may not have an RDAP server yet, since it is a ccTLD it is not bound by ICANN rules.