A simple, configurable and dependency-less Java implementation of the WHOIS protocol.
Inspired by: https://github.com/bestchanges/whoisclient
Before proceeding, it's important to note that the WHOIS protocol serves various purposes beyond domain owner lookups. This library specifically implements the WHOIS protocol as defined in RFC 3912. While it provides a robust foundation for protocol implementation, it may not seamlessly handle certain use cases, such as retrieving detailed domain information due to the commonly adopted "thin WHOIS model." The "thin WHOIS model" requires additional steps, navigating down the hierarchy of servers, to obtain the most accurate information, which is currently not covered by this library. If your use case involves such scenarios, you may need to implement those aspects yourself. I may include an implementation in the library itself in the future.
public class Main {
public static void main(String[] args) throws WhoisIOException {
WhoisClient whoisClient = new WhoisClient(null);
WhoisResponse response = whoisClient.query("bartosz.one", "whois.iana.org");
List<String> nameServers = response.getFields().get("nserver");
System.out.println(String.join(", ", nameServers));
}
}
I'll explain what's going on here:
- class declarations, psvm, you probably know that stuff already. All exceptions the query method throws extend
WhoisIOException
, so it's enough for this example snippet. - I created a new instance of
WhoisClient
with anull
config parameter. Don't worry, it'll just use the default settings. - I queried IANA's WHOIS server (
whois.iana.org:43
) for information about my domain -bartosz.one
. You can skip the WHOIS host declaration in this case, because IANA's server is the default one. Port 43 is also the default, so it's skipped here. - I selected the
nserver
key's value out of thefields
map. The .get() method on this map will always return a list, since WHOIS returns nothing else except these key:value pairs, but keys don't have to be unique, so that's what I settled with as a solution. - Lastly, I joined the list into a readable string and printed it out. The result is a list of .one TLD nameservers,
and that's what you'll usually get when you query IANA's server. However, you can get the key
refer
orwhois
from the map to get the hostname of the next server to query to get more accurate information about the domain.
Maven instructions
- Add my repo to your Maven repositories:
<repository>
<id>bartoszs-repo-releases</id>
<name>bartosz's repo</name>
<url>https://repo.bartosz.one/releases</url>
</repository>
- Add whoisclient to your Maven dependencies: (Remember to replace VERSION with actual version you can see above!)
<dependencies>
<dependency>
<groupId>one.bartosz</groupId>
<artifactId>whoisclient</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
Gradle instructions
- Add my repo to your Gradle repositories:
maven {
url "https://repo.bartosz.one/releases"
}
- Add whoisclient to your Gradle dependencies: (Remember to replace VERSION with actual version you can see above!)
dependencies {
implementation 'one.bartosz:whoisclient:VERSION'
}
Javadocs are available here.
Minimum Java version: Java 8.
The preferred way to get support from me/contact me is joining my Discord server.
Or... email: contact@bartosz.one
Feel free to open issues or PR's.
"whoisclient" is licensed under the MIT License 532E .