Home arrow Delphi-Kylix arrow Page 3 - Creating a WHOIS Lookup Client
DELPHI-KYLIX

Creating a WHOIS Lookup Client


In this article we are going to create a whois lookup client application. The main aim of this application will be to look up information about websites on various known WHOIS servers.

Author Info:
By: Jacques Noah
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
September 18, 2006
TABLE OF CONTENTS:
  1. · Creating a WHOIS Lookup Client
  2. · DNS Resolution
  3. · The Program
  4. · Entire Code

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Creating a WHOIS Lookup Client - The Program
(Page 3 of 4 )

In addition to looking up website information, our application is also going to have the additional functionality of converting hostnames to IP addresses.

Create a new application, and drop 4 Tpanels, two buttons (rename them to "resolve" and "g_info"), a memo, four static labels, three Tedits (rename them to "hostname," "hname" and "dns"), a TCombobox renamed to "cb" and a listview renamed to "lv." Add an idwhois and idDNS component from the Indy Clients tab. Arrange them so that they look something like this:

Finally, add a new form and save it as "addwhois." Put one edit, a button and a label on it. Save it all.

Double click on the GetInfo button and add the following code:

procedure TForm1.g_infoClick(Sender: TObject);
begin
memo1.Clear;
 with IdWhois1 do begin
    Host :=cb.text;
    memo1.Lines.Text := whois(trim(hname.text));
 end;

All that the code above does is look up information about the hostname provided. The hostname above refers to the location of the WHOIS database. Examples include whois.internic.net, arin.net, etc.  The data that is returned is displayed in the memo.

procedure TForm1.resolveClick(Sender: TObject);
var
  Count:     Integer;
  DNSServer: String;
  HostName:  String;
  I:         Integer;
begin
  Memo1.Lines.Clear;
  DNSServer:=dns.Text;
  HostName:=hostnme.Text;
  if (DNSServer='')or(HostName='') then
  begin
    Memo1.Lines.Add('*** Error ***');
    if DNSServer='' then
      Memo1.Lines.Add('DNS Server is empty.');
    if HostName='' then
      Memo1.Lines.Add('Host name is empty.');
    Exit;
   end;
  IdDNSResolver.Host:=DNSServer;
   IdDNSResolver.QueryType:=[qtA];
 IdDNSResolver.Resolve(HostName);
  Count:= IdDNSResolver.QueryResult.Count;
  if Count=0 then Exit;
  for I:=0 to Count-1 do
  begin
        if  IdDNSResolver.QueryResult.Items[I] is TARecord then
    li:=lv.Items.Add;
      with TARecord( IdDNSResolver.QueryResult[I]) do   begin
      li.Caption:=Name;
    li.SubItems.Add(IPaddress);
    end;
    end;
   end;

The code above takes two parameters: dnsserver and the hostname. The dnsserver is typically an IP address, such as 192.168.0.1. This is needed to resolve the given host name to an IP address(es) that will return the requested information from that web site. The host name is any domain name, such as www.mysite.com.

procedure TForm2.Button1Click(Sender: TObject);
begin
form1.cb.items.add(edit1.Text);
close;
end;

The code above allows you to add more WHOIS server locations to the drop down box. The more locations you provide, the fuller the information you get about a specific domain.


blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials