Created
July 9, 2025 14:46
-
-
Save caloni/65be0d7be1bc43ea88282ca073e830ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <windns.h> | |
| #include <iostream> | |
| #pragma comment(lib, "Dnsapi.lib") | |
| #pragma comment(lib, "Ws2_32.lib") | |
| int main() { | |
| PDNS_RECORD pResult = nullptr; | |
| getchar(); | |
| DNS_STATUS status = DnsQuery_W( | |
| L"vmw11-2", | |
| //L"google.com", | |
| DNS_TYPE_A, // DNS_TYPE_AAAA | |
| DNS_QUERY_STANDARD, // DNS_TYPE_TEXT | |
| NULL, | |
| &pResult, | |
| NULL | |
| ); | |
| if (status == 0 && pResult != nullptr) { | |
| PDNS_RECORD pRec = pResult; | |
| while (pRec) { | |
| if (pRec->wType == DNS_TYPE_A) { | |
| IN_ADDR addr; | |
| addr.S_un.S_addr = pRec->Data.A.IpAddress; | |
| std::cout << "IP: " << inet_ntoa(addr) << "\n"; | |
| } | |
| pRec = pRec->pNext; | |
| } | |
| DnsRecordListFree(pResult, DnsFreeRecordList); | |
| } else { | |
| std::cerr << "DnsQuery_W failed: " << status << "\n"; | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment