65.9K
CodeProject is changing. Read more.
Home

Creating a global Whois class

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.90/5 (9 votes)

Dec 7, 2003

1 min read

viewsIcon

72254

downloadIcon

1342

Lookup a domain name for any tld (top level domain)

Introduction

I realise there is already a Whois example for C# on codeproject, in the form of an asp.net snippet. The class I've posted here encapsulates a little more functionality than that example, and is taken from a Perl script i wrote a few years back.

Details

The Whois class has one main method, Lookup(domain). From this, the class works out what whois server should be used for the domain lookup. This is done by a trick taken from the Perl script, the service is provided by whois-servers.net, hosted by CenterGate. From performing a dns lookup on the domain name's tld (e.g. .com for mydomain.com), attached to .whois-servers.net, you're provided with the address of the whois server for that domain, if one exists.

I've built into the class, the ability to provide your own whois server, via the WhoisServer property. I've also added checks for a few domain names which don't provide free whois servers, and the .tk domain which does, but isn't on the whois-servers.net service.

The class performs the lookup, and raises an event, LookupComplete when it's finished, passing a WhoisEventArgs class with it, which provides the results of the lookup, and the whois server that was used.

To check whether a domain is taken or not, is up to you - you'll have to parse the string provided in the WhoisInfo property of the WhoisEventArgs class.

The example project is a small windows forms application, to demonstrate how to use the class. The class doesn't cater for non-resolving whois servers at present, it could perhaps do with a few more lines of error trapping in this area.