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.
Next: Entire Code >>
More Delphi-Kylix Articles
More By Jacques Noah