Unit Udns;
interface
uses windows, sysutils, Classes;
const
MAX_HOSTNAME_LEN = 128; { from IPTYPES.H }
MAX_DOMAIN_NAME_LEN = 128;
MAX_SCOPE_ID_LEN = 256;
MAX_ADAPTER_NAME_LENGTH = 256;
MAX_ADAPTER_DESCRIPTION_LENGTH = 128;
MAX_ADAPTER_ADDRESS_LENGTH = 8;
type
TIPAddressString = array[0..4 * 4 - 1] of Char;
PIPAddrString = ^TIPAddrString;
TIPAddrString = record
Next: PIPAddrString;
IPAddress: TIPAddressString;
IPMask: TIPAddressString;
Context: Integer;
end;
PFixedInfo = ^TFixedInfo;
TFixedInfo = record { FIXED_INFO }
HostName: array[0..MAX_HOSTNAME_LEN + 3] of Char;
DomainName: array[0..MAX_DOMAIN_NAME_LEN + 3] of Char;
CurrentDNSServer: PIPAddrString;
DNSServerList: TIPAddrString;
NodeType: Integer;
ScopeId: array[0..MAX_SCOPE_ID_LEN + 3] of Char;
EnableRouting: Integer;
EnableProxy: Integer;
EnableDNS: Integer;
end;
function GetDNSList(aDNSList: tstringlist): boolean;
function GetNetworkParams(FI: PFixedInfo; var BufLen: Integer): Integer; stdcall; external 'iphlpapi.dll';
implementation
function GetDNSList(aDnsList: tstringlist): boolean;
var
FI: PFixedInfo;
Size: Integer;
Res: Integer;
// I: Integer;
DNS: PIPAddrString;
begin
Size := 1024;
GetMem(FI, Size);
Res := GetNetworkParams(FI, Size);
if (Res <> ERROR_SUCCESS) then begin
result := false;
SetLastError(Res);
// RaiseLastWin32Error;
exit;
end;
aDnsList.Clear;
// I := 1;
DNS := @FI^.DNSServerList;
repeat
aDnsList.Add(DNS^.IPAddress);
// Inc(I);
DNS := DNS^.Next;
until (DNS = nil);
FreeMem(FI);
result := true;
end;
end.