Solved

finding address of NICs DNS servers

Posted on 2002-03-18
16
319 Views
Last Modified: 2013-12-03
How do I programically find the address's of the configured DNS servers in winsock 1.1.  I can find all other relavent info using GetAdaptersInfo. I'm using VC++ 6.

Thanks in advance..

Chris
0
Comment
Question by:sads
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
  • +1
16 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6877419
You could use 'GetAdaptersInfo()' from the IP helper API: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_6tpr.asp

An overview can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/ipover_394j.asp ("Managing Network Adapters")
0
 
LVL 32

Expert Comment

by:jhance
ID: 6877541
The problem with the IPHLPAPI.DLL is that it's not available on your platform.  Since you're using WINSOCK 1.1 I'm assuming it's Win95 and you don't have access to it.  

The best approach in this instance is to use the WINIPCFG with its output directed to a file.  Then you can parse the file for the DNS server information.

Use something like:

system("WINIPCFG /ALL /BATCH");

will dump the output to WINIPCFG.OUT.  There you can easily find the DNS server(s) for the system.  In WINSOCK 1.1 there is only global DNS setting that is shared by all network adapters on the system.
0
 
LVL 32

Expert Comment

by:jhance
ID: 6877557
Alternatively, on WINSOCK 1.1 systems you can locate the DNS server(s) from the registry at:

HLM\System\CurrentControlSet\Services\VxD\MSTCP and the NameServer value you'll find there.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

Author Comment

by:sads
ID: 6878066
I have asked this question twice (by accident). Refer to the other question. Sorry, its been a bad day.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6878093
Hum, why are you trying to delete this one as it contains a solution that works on XP (as you mentioned that in the other Q)? See my above comment...
0
 

Author Comment

by:sads
ID: 6878115
I am already using that call (see the question).  It gets me everthing I need, but it does not return the DNS entries (unless its well hidden).  Thats what I'm looking for, the DNS entries.

I somehow asked this question 2 times (and got **** for it).  So I just picked one to delete and this was it.

Thanks

Chris
0
 
LVL 86

Expert Comment

by:jkr
ID: 6878138
>>unless its well hidden

Not really :o)

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_6ptf.asp ("IP_ADAPTER_DNS_SERVER_ADDRESS")

And it seems that it was my fault, I thought of 'GetAdaptersAddresses()' (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tcpip/tcpip_2joz.asp), but wroute '...AdapterInfo()' :o)
0
 

Author Comment

by:sads
ID: 6878156
Does this not need a define (see the h file) that requires winsock 2?  
0
 
LVL 86

Expert Comment

by:jkr
ID: 6878161
I don't have the .h file here at the moment, but the MS docs are pretty clear:

Requirements
  Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
  Windows 95/98/Me: Unsupported.
  Header: Declared in Iphlpapi.h.
  Library: Use Iphlpapi.lib.
0
 

Author Comment

by:sads
ID: 6878186
I have tried the below, but again winsock2....



#ifdef _WINSOCK2API_

//
// The following functions require Winsock2.
//

DWORD
WINAPI
GetAdaptersAddresses(
    ULONG Family,
    DWORD Flags,
    PVOID Reserved,
    PIP_ADAPTER_ADDRESSES pAdapterAddresses,
    PULONG pOutBufLen
    );

#endif

DWORD
WINAPI
GetPerAdapterInfo(
    ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen
    );

DWORD
0
 
LVL 86

Expert Comment

by:jkr
ID: 6878212
Hmmm.. so, why don't you just

#define _WINSOCK2API_

before including the header file?
0
 

Author Comment

by:sads
ID: 6878572
Yup I tried that, then went full out on winsock2 and got shot down by the implementation team as to not wanting to update to winsock2 on the older 98 machines.  So I went back to the drawing board thinking there must be source for a nslookup etc etc, but so far that two has come up empty...

Thanks for you input so far, It did make me go back to see if I missed anything...
0
 
LVL 22

Accepted Solution

by:
cookre earned 200 total points
ID: 6881607
Actually, you can get the DNS IPs under Winsock 1.1 from 9x, NT, or 2k.

First off, include winsock.h and link with wsock32.lib.

First, determine which OS you're running under with GetVersionEx().

Then, for 2K:
Look at HKLM\System\CurrentControlSet\Services\NetBT\Linkage
Value 'Route' has two strings embedded.  We'll call the first one <Service> and the second <ClassID>.

Now go to key HKLM\System\CurrentControlSet\Services\NetBT\Parameters\Interfaces\<NewKeyNode>

where <NewKeyMode> is the above <Service>_<ClassID>

Look in value NameServer.  If nothing is there, look in value NameServerList.

If NameServerList is valued, it may have multiple IPs seperated by spaces.


For NT:
Look at value Route from the same key as above.

This 'Route' is a list of adapter names corresponding to NICs that have been in the box.  For each NIC name in 'Route', look for the corresponding key:
HKLM\System\CurrentControlSet\Services\NetBT\Adapters\<CurrentNICNameExtractedFromRoute>

(if the box has multiple NICs, you get multiple hits.  Some tries will fail - those are NICs that used to be in the box, but aren't there any longer.

Under that (or each) key, the values to look at are NameServer and NameServerBackup.

Under 95:

Get key HKLM\System\CurrentControlSet\Services\VxD\MSTCP
value NameServer (as jhance mentioned)


Note that all of this relies on DNS being enabled with defined IPs.  If DNS is enabled through DHCP, the values are stored elsewhere (I'll get those from work tomorrow).

If DNS is disabled and name resolution handled via WINS, the IPs are stored under yet different  values.  Those I haven't bothered to research since the boxes I wrote this for (about 120,000 desktops of various flavors) are supposed to have DNS enabled.
0
 

Author Comment

by:sads
ID: 6882399
Thanks very much.

Chris
0
 
LVL 22

Expert Comment

by:cookre
ID: 6882711
As promised, for boxes set to get DNS via DHCP:

2K:
Value DhcpNameServerList

HKLM\System\CurrentControlSet\Services\TcpIp\Parameters\Interfaces\<Class>
value DhcpNameServer

This ClassID is the <Class> from <Service>_<Class> mentioned above.

NT:
Values DhcpNameServer and DhcpNameServerBackup


95:
No option for DNS via DHCP
0
 

Author Comment

by:sads
ID: 6882724
Very cool

Thanks a lot.  I appreciate the effort.

Chris
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question