i do not have delphi at hand, so here is code that does what you want, convert domain-name (example: google.com) into ip-adress.
unicode, ip4 & ip6 supported
uses
Winapi.Winsock2;
type
PAddrInfo = ^TAddrInfo;
TAddrInfo = packed record
ai_flags: integer;
ai_family: integer;
ai_socktype: integer;
ai_protocol: integer;
ai_addrlen: NativeInt;
ai_canonname: PCHAR;
ai_addr: PSOCKADDR;
ai_next: PAddrInfo;
end;
function GetAddrInfo(const nodeName: PCHAR; const serviceName : PChar; const hints: PAddrInfo; var result: PAddrInfo): integer; stdcall; external 'ws2_32.dll' name 'GetAddrInfoW';
procedure FreeAddrInfo(const addrInfo: PAddrInfo); stdcall; external 'ws2_32.dll' name 'FreeAddrInfoW';
function ResolveIpAddress(const hostName: string; const ipv6: boolean): string;
const
BUFFER_SIZE = 32768;
var
data: TWSAData;
error: integer;
requestError: integer;
r: PAddrInfo;
s: string;
hints: TAddrInfo;
buffer: TArray<byte>;
length: DWORD;
begin
error:= WSAStartup(MAKEWORD(2, 2), data);
try
if (error = 0) then
begin
r:= nil;
try
ZeroMemory(@hints, sizeof(TAddrInfo));
if (ipv6) then
hints.ai_family:= AF_INET6
else
hints.ai_family:= AF_INET;
requestError:= GetAddrInfo(PCHAR(hostName), nil, @hints, r);
if (requestError = 0) then
begin
length:= BUFFER_SIZE;
SetLength(buffer, BUFFER_SIZE);
if (WSAAddressToString(r.ai_addr^, r.ai_addrlen, nil, @buffer[0], length) = 0) then
begin
setLength(buffer, length * 2);
s:= TUnicodeEncoding.Unicode.GetString(@buffer[0]);
exit(s);
end
else
exit('0.0.0.0');
end
else
exit('0.0.0.0');
finally
FreeAddrInfo(r);
end;
end
finally
if (error = 0) then
WSACleanup();
end;
end;
if 0.0.0.0 is returned, there was an error