| |

VerySource

 Forgot password?
 Register
Search
View: 769|Reply: 4

How to get DNS without reading the registry

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-1 16:00:01
| Show all posts |Read mode
How to get DNS value without reading the registry
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-20 23:45:01
| Show all posts
DWORD GetNetworkParams (
  PFIXED_INFO pFixedInfo,
  PULONG pOutBufLen
);

#include <stdio.h>
#include <windows.h>
#include <iphlpapi.h>

#program comment (lib, "iphlpapi.lib")

main () {
   
   FIXED_INFO * FixedInfo;
   ULONG ulOutBufLen;
   DWORD dwRetVal;
   IP_ADDR_STRING * pIPAddr;

   FixedInfo = (FIXED_INFO *) GlobalAlloc (GPTR, sizeof (FIXED_INFO));
   ulOutBufLen = sizeof (FIXED_INFO);
   
   if (ERROR_BUFFER_OVERFLOW == GetNetworkParams (FixedInfo,&ulOutBufLen)) {
      GlobalFree (FixedInfo);
      FixedInfo = (FIXED_INFO *) GlobalAlloc (GPTR, ulOutBufLen);
   }

   if (dwRetVal = GetNetworkParams (FixedInfo,&ulOutBufLen)) {
        printf ("Call to GetNetworkParams failed. Return Value:% 08x\n", dwRetVal);
   }
   else {
      printf ("Host Name:% s\n", FixedInfo-> HostName);
      printf ("Domain Name:% s\n", FixedInfo-> DomainName);
      
      printf ("DNS Servers:\n");
      printf ("\t% s\n", FixedInfo-> DnsServerList.IpAddress.String);
      
      pIPAddr = FixedInfo-> DnsServerList.Next;
      while (pIPAddr) {
         printf ("\t% s\n", pIPAddr-> IpAddress.String);
         pIPAddr = pIPAddr-> Next;
      }
   }
   exit (0);
}
To install sdk
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-23 20:15:02
| Show all posts
This seems to only get one DNS, what if it is a dual network card?
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-30 10:45:01
| Show all posts
I tried two network cards.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-5-7 08:00:01
| Show all posts
That's it
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list