Win a copy of Terraform in Action this week in the Cloud forum!
    Bookmark Topic Watch Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
There are numerous sample codes floating around the web that show how to do a Whois lookup, but none seem to get it quite right. So here's code that works for all TLDs, and also smoothes out some of the peculiarities of various Whois servers. It uses the Apache Commons Net library (which by itself does not implement a comprehensive lookup solution).

The general approach is:

  • Perform a Whois lookup against the IANA server at; the result will point to the authoritative Whois server for the domain in question.
  • Extract the server name from the response, and then perform a lookup against that server.
  • This response may point to a more specific Whois server that has additional information, often run by the host's registrar. If it does, an additional lookup is performed against that server.

  • Additional difficulties to watch out for:

  • The Whois server for the ".jp" TLD returns Japanese characters, which is generally not wanted; so an option is used to turn that off.
  • The server handling the ".de" TLD needs an additional flag passed in, or nothing will be returned. Also, after a few lookups, this server stops returning results to a particular IP address for a while; so be careful how many requests for ".de" domains you send.
  • The results for various domains (like,, etc.) contain bogus subdomains that prevent proper results for the actual domain from being returned; so a special syntax is used to filter out those junk entries for the ".com" TLD.
  • An additional option is passed on for ".dk" domains so that more information is shown for them.

  • CodeBarn CategoryCodeSamples
      Bookmark Topic Watch Topic
    • New Topic