I am working on an application that is suppose to return the expiration date of a Domain name. I used the getExpiration() but it keeps returning 0 for any site that I plug in. EX: http://www.google.com expires 2020-09-13, but when I run my code it returns 0 meaning it’s not known. Does anyone know of any other methods to get the expiration date of a Domain name? Any help would be greatly appreciated.
try
{
URL url = new URL("http://"+ hostname +":80");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
long date = connection.getExpiration();
if (date == 0)
System.out.println("Expiration unknown.");
else
System.out.println("Expires: " + new Date(date));
catch (Exception e)
{ // ...
}
The “expiration date” for domain names is available through the Whois protocol. Note that not all domain registries expose the domain expiration date, and those that do expose it might do so in different ways.
There may be a Java library that simplifies access to the Whois services; I don’t know. Such a thing should be easy to search for.