Gönderen Konu: get the local DNS servers list?  (Okunma sayısı 715 defa)

Çevrimdışı nadir_pıero

  • Osc Çizik Üye

  • 3. SINIF UYE
  • *
  • İleti: 3.539
  • Puan -101
  • Cinsiyet: Bay
    • MSN Messenger - nadir_piero10@hotmail.com
    • Profili Görüntüle
    • E-Posta
get the local DNS servers list?
« : 04 Aralık 2006, 08:54:33 »
unit iphlp;

interface

uses Windows, System;

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(AList: TStringList);


implementation

const
  {$IFDEF MSWINDOWS}
  iphlpapidll = 'iphlpapi.dll';
  {$ENDIF}

function GetNetworkParams; external iphlpapidll Name 'GetNetworkParams';


procedure GetDNSServers(AList: TStringList);
var
  pFI: PFixedInfo;
  pIPAddr: PIPAddrString;
  OutLen: Cardinal;
begin
  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;
end;

end.

Çevrimdışı LeGeND-MæN

  • 1. SINIF ÜYE
  • *****
  • İleti: 25.719
  • Puan 1937
  • Cinsiyet: Bay
  • Mangal Yürekli Adam
    • Profili Görüntüle
get the local DNS servers list?
« Yanıtla #1 : 03 Mart 2007, 14:36:21 »
emeğine sağlık..
tarz yaratmak için Ağır Abi OLma!! Ağır Abi Dediğin Sevdimi Tam Sever Giydiğini herkez Beğenir, Saygısı Sonsuz Sevgisi Ebedi Olur..

DAĞLARINA DARGIMIM YAR...



Çevrimdışı N0RM

  • 2. SINIF UYE
  • ****
  • İleti: 6.136
  • Puan 310
  • Cinsiyet: Bay
  • Narq0z
    • Profili Görüntüle
    • E-Posta
get the local DNS servers list?
« Yanıtla #2 : 06 Nisan 2007, 21:39:34 »
paylaşım için saol