![]() |
DNS-Einstellungen der Netzwerkadapter auslesen/ändern
Hi!
Ich suche nach einer Möglichkeit, die DNS-Server-Einstellungen der Netzwerkadapter unter Win7 mit Delphi auszulesen, bzw. diese zu ändern. Leider finde ich mit der Forensuche nichts gescheites darüber. Ich könnte also etwas Hilfe dabei gebrauchen. Gruß aus Hamburg! |
Re: DNS-Einstellungen der Netzwerkadapter auslesen/ändern
Ich habe
![]()
Delphi-Quellcode:
[edit] Ob und wie sich diese Einstellungen ändern lassen, konnte ich auf die Schnelle allerdings nicht herausfinden. [/edit]
unit iphlp;
interface uses Windows, SysUtils, Classes; const MAX_HOSTNAME_LEN = 128; MAX_DOMAIN_NAME_LEN = 128; MAX_SCOPE_ID_LEN = 256; type // // TIPAddressString - store an IP address or mask as dotted decimal string // PIPAddressString = ^TIPAddressString; PIPMaskString = ^TIPAddressString; TIPAddressString = record _String: array[0..(4 * 4) - 1] of Char; end; TIPMaskString = TIPAddressString; // // TIPAddrString - store an IP address with its corresponding subnet mask, // both as dotted decimal strings // PIPAddrString = ^TIPAddrString; TIPAddrString = packed record Next: PIPAddrString; IpAddress: TIPAddressString; IpMask: TIPMaskString; Context: DWORD; end; // // FIXED_INFO - the set of IP-related information which does not depend on DHCP // PFixedInfo = ^TFixedInfo; TFixedInfo = packed record HostName: array[0..MAX_HOSTNAME_LEN + 4 - 1] of Char; DomainName: array[0..MAX_DOMAIN_NAME_LEN + 4 - 1] of Char; CurrentDnsServer: PIPAddrString; DnsServerList: TIPAddrString; NodeType: UINT; ScopeId: array[0..MAX_SCOPE_ID_LEN + 4 - 1] of Char; EnableRouting, EnableProxy, EnableDns: UINT; end; function GetNetworkParams(pFixedInfo: PFixedInfo; pOutBufLen: PULONG): DWORD; stdcall; // Get machine DNS Servers and return them in the provided StringList. This list should have been // already created by the calling program before performing this call procedure GetDNSServers(const AList: TStrings); implementation const {$IFDEF MSWINDOWS} iphlpapidll = 'iphlpapi.dll'; {$ENDIF} function GetNetworkParams; external iphlpapidll Name 'GetNetworkParams'; procedure GetDNSServers(const AList: TStrings); var pFI: PFixedInfo; pIPAddr: PIPAddrString; OutLen: Cardinal; begin if not Assigned(AList) then raise Exception.Create('AList is not Assigned'); AList.BeginUpdate; try AList.Clear; OutLen := SizeOf(TFixedInfo); GetMem(pFI, SizeOf(TFixedInfo)); try if GetNetworkParams(pFI, @OutLen) = ERROR_BUFFER_OVERFLOW then begin ReallocMem(pFI, OutLen); if GetNetworkParams(pFI, @OutLen) <> NO_ERROR then Exit; end; // If there is no network available there may be no DNS servers defined if pFI^.DnsServerList.IpAddress._String[0] = #0 then Exit; // Add first server AList.Add(pFI^.DnsServerList.IpAddress._String); // Add rest of servers pIPAddr := pFI^.DnsServerList.Next; while Assigned(pIPAddr) do begin AList.Add(pIPAddr^.IpAddress._String); pIPAddr := pIPAddr^.Next; end; finally FreeMem(pFI); end; finally AList.EndUpdate; end; end; end. |
Re: DNS-Einstellungen der Netzwerkadapter auslesen/ändern
Dieser Code leifert bei mir leider immer eine Leere Liste zurück, an dieser stelle wird die Prozedur einfach beendet:
Delphi-Quellcode:
// If there is no network available there may be no DNS servers defined
if pFI^.DnsServerList.IpAddress._String[0] = #0 then Exit; |
Re: DNS-Einstellungen der Netzwerkadapter auslesen/ändern
Die folgenden WinAPI-Befehle
![]() ![]() ![]() ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:47 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz