Click here to Skip to main content
15,891,717 members
Articles / Desktop Programming / MFC
Article

WhoIS Class for MFC

Rate me:
Please Sign up or sign in to vote.
4.36/5 (8 votes)
29 Feb 2000 93.9K   1.4K   38   13
A simple MFC class for WhoIS processing for the Internet.
  • Download demo project - 44 Kb
  • Sample Image - Whois.jpg

    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:

    // Create class instance
    CWhoIsClass whoIs;
    
    // Set address to be queried
    CString szAddress = "Microsoft.com";
    
    // Call actual function
    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.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Web Developer
    United States United States
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    GeneralNew whois server URL Pin
    dimag30-May-07 7:57
    dimag30-May-07 7:57 
    Generalbeginer Pin
    dnqhung12-Jun-04 20:31
    dnqhung12-Jun-04 20:31 
    GeneralCWhoIsClass::WhoIs Bug Pin
    qiek19-Feb-04 18:30
    qiek19-Feb-04 18:30 
    GeneralNeat !! Pin
    WREY12-Apr-03 23:05
    WREY12-Apr-03 23:05 
    GeneralUnable to use IP Address Pin
    M.Fletcher6-Jun-02 19:11
    M.Fletcher6-Jun-02 19:11 
    Generalserver to connect to get info Pin
    pankaj24-Sep-01 21:59
    pankaj24-Sep-01 21:59 
    GeneralRe: server to connect to get info Pin
    Laurent Sarrazin1-Oct-01 2:17
    Laurent Sarrazin1-Oct-01 2:17 
    GeneralRe: server to connect to get info Pin
    16-Jan-02 16:19
    suss16-Jan-02 16:19 
    GeneralThe App Runs only with MFC42D.dll Pin
    Sujatha Bhandari3-Jun-00 3:41
    sussSujatha Bhandari3-Jun-00 3:41 
    GeneralRe: The App Runs only with MFC42D.dll Pin
    27-Jun-01 4:07
    suss27-Jun-01 4:07 
    GeneralRe: The App Runs only with MFC42D.dll Pin
    Ed Dixon27-Jun-01 4:10
    Ed Dixon27-Jun-01 4:10 
    GeneralWhois Class Pin
    dadams076-Mar-00 4:19
    dadams076-Mar-00 4:19 
    GeneralRe: Whois Class Pin
    Ed Dixon6-Mar-00 17:44
    Ed Dixon6-Mar-00 17:44 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.