function GetDNS: string; {$IFDEF LINUX} var l: TStringList; n: integer; begin Result := ''; l := TStringList.Create; try l.LoadFromFile('/etc/resolv.conf'); for n := 0 to l.Count - 1 do if Pos('NAMESERVER', uppercase(l[n])) = 1 then begin if Result <> '' then Result := Result + ','; Result := Result + SeparateRight(l[n], ' '); end; finally l.Free; end; end; {$ELSE} const NTdyn = 'System\CurrentControlSet\Services\Tcpip\Parameter s\Temporary'; NTfix = 'System\CurrentControlSet\Services\Tcpip\Parameter s'; W9xfix = 'System\CurrentControlSet\Services\MSTCP'; begin Result := GetDNSbyIpHlp; if Result = '...' then if Win32Platform = VER_PLATFORM_WIN32_NT then begin Result := ReadReg(NTdyn, 'NameServer'); if result = '' then Result := ReadReg(NTfix, 'NameServer'); end else Result := ReadReg(W9xfix, 'NameServer'); end; {$ENDIF}
{$IFDEF LINUX}
var
l: TStringList;
n: integer;
begin
Result := '';
l := TStringList.Create;
try
l.LoadFromFile('/etc/resolv.conf');
for n := 0 to l.Count - 1 do
if Pos('NAMESERVER', uppercase(l[n])) = 1 then
begin
if Result <> '' then
Result := Result + ',';
Result := Result + SeparateRight(l[n], ' ');
end;
finally
l.Free;
end;
end;
{$ELSE}
const
NTdyn = 'System\CurrentControlSet\Services\Tcpip\Parameter s\Temporary';
NTfix = 'System\CurrentControlSet\Services\Tcpip\Parameter s';
W9xfix = 'System\CurrentControlSet\Services\MSTCP';
begin
Result := GetDNSbyIpHlp;
if Result = '...' then
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
Result := ReadReg(NTdyn, 'NameServer');
if result = '' then
Result := ReadReg(NTfix, 'NameServer');
end
else
Result := ReadReg(W9xfix, 'NameServer');
end;
{$ENDIF}
http://search.csdn.net/Expert/topic/677/677230.xml?temp=.7453882