Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

current dns server

hi im looking for a way to get the current dns server, anyone ? does anyone no any freeware components or code ? any help appreciated.
0
adrenalindx
Asked:
adrenalindx
1 Solution
 
Wax0rCommented:
It's available in the registry.


HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\NetBT\Parameters\Interfaces\

has some TCP_IP subkeys, enumerate them and check for the NameServerList string, it holds the nameservers :)
0
 
adrenalindxAuthor Commented:
yes but this does not allways work, anything else ? there is a way to do it like winipcfg does it it required the iphlpapi or something ??
0
 
MunimCommented:
This code should work...

--begin of code--
program dnslist;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows, Iphlpapi, Ipexport, IpTypes;

var
  pFixedInfo: PFIXED_INFO;
  pDnsInfo: PIP_ADDR_STRING;
  BufLen, Ret: DWORD;
  Cnt: Integer;
begin
  ret := GetNetworkParams(nil, @BufLen);
  if ret <> ERROR_BUFFER_OVERFLOW then
    Exit;
  GetMem(pFixedInfo, BufLen);

  ret := GetNetworkParams(@pFixedInfo, @BufLen);
  if ret <> ERROR_SUCCESS then
    Exit;

  pDnsInfo := @(pFixedInfo^.DnsServerList);
  if pDnsInfo^.IpAddress.S[0] = #0 then
    Writeln('DNSƒT[ƒo‚͐ݒ肳‚ê‚Ä‚¢‚Ü‚¹‚ñB');

  Cnt := 1;
  repeat
    Writeln('DNSƒT[ƒo' + IntToStr(Cnt) + ' = ' + pDnsInfo^.IpAddress.S);
    pDnsInfo := pDnsInfo^.Next;
    Inc(Cnt);
  until pDnsInfo = nil;
end.
--end of code--
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
adrenalindxAuthor Commented:
thanks ill check it out and get back to u,
0
 
adrenalindxAuthor Commented:
i tried to compile like this but it wood not work and had to do this


 ret := GetNetworkParams(@pFixedInfo, @BufLen);


to


 ret := GetNetworkParams(pFixedInfo, BufLen);

i got rid of the @ otheriwse it wont compile

wen i run it it crashes, not crashes but raises an exception ??
0
 
CleanupPingCommented:
adrenalindx:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
snehanshuCommented:
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
http://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

To be deleted and points refunded

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
0
 
Lukasz LachCommented:
0
 
moduloCommented:
PAQed, with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now