Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
DNS Lookup
Do a DNS lookup to resolve a hostname to an IP address.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Socket;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
socket: TSocket;
maxWaitMs: Integer;
ipAddr: string;
begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
socket := TSocket.Create;
maxWaitMs := 10000;
ipAddr := socket.DnsLookup('www.chilkatsoft.com',maxWaitMs);
if (socket.LastMethodSuccess <> True) then
begin
WriteLn(socket.LastErrorText);
Exit;
end;
WriteLn('IP Address: ' + ipAddr);
socket.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.