Download demo project - 44 Kb
This is a simple MFC class for Internet-based WhoIs processing. WhoIs is
an internet function to determine information about specific IP addresses and
domain names. A number of companies, such as NetworkSolutions and Internic,
keep WHOIS databases online at all times. While many freeware applications
exist to display this data, there is little information or code available
that actually does it.
Many applications need access to this information, and this class provides a
simple way to query these databases. The code to use this class to access
this information would look like the following:
CWhoIsClass whoIs;
CString szAddress = "Microsoft.com";
CString szResult = whoIs.WhoIs(szAddress);
There are only two public functions for the class:
CString WhoIs(LPCSTR szAddress);
void SetWhoIsServer(LPCSTR szServerName);
The first is used to obtain the WhoIs information. The data is returned
as a string that is typically a few hundred characters.
The second is used to change WhoIs servers. The program defaults to the
whois.internic.net server. You can change it to whatever whois server
best fits your needs. The Internic and Network Solutions servers host
mostly US sites. Other servers exist to handle military address and
international addresses. You should probably expect to query two or more
servers to obtain the best information.
When querying a whois server, you can request either domain name information
(eg. microsoft.com) or IP address information (eg. 216.98.67.204). For
example, the following would be valid address queries:
whois("microsoft.com")
whois("codedeveloper.com")
but
whois("www.microsoft.com")
would be an invalid query request.
Most whois servers appear to accept the domain portion (minus the "www." part)
and return valid information. The query syntax for IP address requests
varies by whois server The whois.internic.net server accepts pure IP
address queries. The whois.networksolutions.com server however requires
that the word "host" preceed the IP portion. If you use the network solutions
whois server, which sometimes returns more complete information, your queries
would have to take the following form:
whois(host 216.98.67.204)
If the "host" part is missing, no data will be returned with using the
whois.networksolutions.com server.
Using the code in your project also requires you include the source and
header files for the CWhoIsClass
. This would usually look like
this:
#include "WhoIsClass.h"
#include "WhoIsClass.cpp"
The code was compiled with VC++ 6.0, but should work with earlier versions as
well. It uses MFC sockets for processing, and therefore requires a
AfxSocketInit()
call prior to class use. It assumes a connection
to the Internet already exists.
That's it. Not very complicated, but it solved my problem. Perhaps it will help
others as well.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.