Build a DNS server that responds with an in-memory list of IPs based on the name submitted.

 
This sample represents a DNS server that responds with an in-memory list of IPs based on the name submitted.
In short, you need to use the OnGetHandedRecords event of the TclDnsServer component. The event handler may look like the following:
 
procedure TForm1.clDnsServer1GetHandedRecords(Sender: TObject;
   AConnection: TclUdpUserConnection; const AName: string; ARecords: TclDnsRecordList);
var
   rec: TclDnsARecord;
begin
   ARecords.Clear();
 
   rec := TclDnsARecord.Create();
   ARecords.Add(rec);
 
   rec.Name := AName;
   rec.IPAddress := '111.222.333.444';
   rec.TTL := 60000;
end;
For sure, the complete DNS server should analyze the AName parameter, should add additional DNS records, such as SOA, NS and possible MX.
 
Please download the complete sample by using the link above.
 
See also the following article: Simple DNS Server in Delphi

Add Feedback