Go Premium for a chance to win a PS4. Enter to Win

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

finding address of NICs DNS servers

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
sads
Asked:
sads
  • 7
  • 5
  • 2
  • +1
1 Solution
 
jkrCommented:
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
 
jhanceCommented:
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
 
jhanceCommented:
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
sadsAuthor Commented:
I have asked this question twice (by accident). Refer to the other question. Sorry, its been a bad day.
0
 
jkrCommented:
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
 
sadsAuthor Commented:
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
 
jkrCommented:
>>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
 
sadsAuthor Commented:
Does this not need a define (see the h file) that requires winsock 2?  
0
 
jkrCommented:
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
 
sadsAuthor Commented:
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
 
jkrCommented:
Hmmm.. so, why don't you just

#define _WINSOCK2API_

before including the header file?
0
 
sadsAuthor Commented:
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
 
cookreCommented:
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
 
sadsAuthor Commented:
Thanks very much.

Chris
0
 
cookreCommented:
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
 
sadsAuthor Commented:
Very cool

Thanks a lot.  I appreciate the effort.

Chris
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 7
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now