What is Whois ?
Whois is a protocol to fetch the registered users of a internet resource such as a domain name or an IP block, it is documented in RFC 3912.
Whois information can be used to know some basic information about a domian name like the person or the organization it is registered to, registration & expiry date etc.,
One of the popular use case for the whois information is to check the availability of a domain name, you can read more about this in my other post.
The whois protocol is a pretty straight forward TCP based query response protocol, each TLD or top level domain(example .com, .net, .org, etc., ) will have a whois server that will listen on the port number 43 for the queries, Once a request is received the server will check its internal database for the domain name details and return the information in the response, the availability of a domain name in a particular TLD can be identified from the whois information returned, the structure of the whois might differ from server to server.
The protocol can be explained simply as follows
Connect to the service host
TCP: service port 43 decimal
Send a single "command", ending with a new line character(ASCII CR and then ASCII LF)
Receive information in response to the command line. The
server closes its connections as soon as the output is
Implementation In C#
To get the Whois information of any domain, we need 3 parameters
- Domain name
- Record type, which is “domain”
- The whois server address for the TLD of the given domain name
A collection of Whois server list is maintained by nirsoft.net which we can use to determine the correct Whois server for a given domain name based on its TLD
Once we get this, all we have to do is connect to the server on port 43 using TCP and send the query as combination of the text “domain” and your domain name, seperated by a single space character ” “, your query should always end with a new line character.
You can get the whois information by just calling the Whois.Lookup method with your domain name as parameter as shown in the code below.
Please note that this is implementation works only “.com” TLD domains, you have to change the server name to make it work for other TLD’s, you can find the implementation which works with different TLD’s in the github project I linked below
This post is originally published on coderbuddy.wordpress.com.