Recently I was searching for domain names out on the interwebs and realized there was no good way (I could find) to search for possible domain names in bulk. For example, I wanted to type in “nathan” into some awesome app and have it tell me all of the domain extensions (TLDs) that were available for purchase. So, I threw together a C# app just for that purpose and wanted to share the process here.
In order to check for a domain’s availability, we’ll need to make two calls out to the internet. First, we’ll want to grab the whois server that is used with the TLD you’re searching for (.com, .coffee, .etc). This server is responsible for telling us who, if anyone, has the domain name registered. After we retrieve the whois server to use, we’ll make a second call out to that server to check for registration on the domain we’re searching for.
Now, for some code. The first thing we’re going to do is create a method that will make a request out to our whois server and return the result.
The main takeaway from this method is that we’re going to open a TCP connection to our whois server, request information about our query, and then read the results back.
Now that the core method is set up, we’ll want to stash the root whois server in a variable. This server will be the one responsible for telling us which whois server we should use to check for the domain itself.
Next, we’ll set up our initial method that we can call to check for a domain names’ availability. This method will take two parameters: a keyword and a TLD.
As stated above, the first thing we need to do is retrieve the whois server that is associated with the TLD that we are searching for. Add the following code into our IsAvailable method:
If we were to query our root whois server with .coffee, the results would look like this:
If you look back at the code we have, the only thing we care about is that first line. This is the whois server URL that we are going to want for our next call.
Next, we’re going to make a call out to the whois server retrieved above and check for a registration for the domain we’re trying to check. Add this code into our IsAvailable method to do so:
Now, if we were to query for nathanloves.coffee, we would get some results back that look like this (at the time of writing):
Throwing this all together, we end up with this:
Pretty easy right? Now to use this, all you have to do is call it like so: