Created
February 4, 2023 17:11
-
-
Save R3DHULK/be34aa9d5938846cdc41953cdcbb5207 to your computer and use it in GitHub Desktop.
DNS Enumeration In CPP
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 <iostream> | |
#include <string> | |
#include <netdb.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
#include <cstring> | |
using namespace std; | |
int main(int argc, char *argv[]) | |
{ | |
if (argc < 2) | |
{ | |
cout << "Usage: " << argv[0] << " <domain-name>" << endl; | |
return 1; | |
} | |
string domainName = argv[1]; | |
struct hostent *hostInfo; | |
hostInfo = gethostbyname(domainName.c_str()); | |
if (!hostInfo) | |
{ | |
cout << "Could not retrieve information for domain: " << domainName << endl; | |
return 1; | |
} | |
cout << "IP addresses for " << domainName << ":" << endl; | |
for (int i = 0; hostInfo->h_addr_list[i]; i++) | |
{ | |
struct in_addr addr; | |
memcpy(&addr, hostInfo->h_addr_list[i], sizeof(struct in_addr)); | |
cout << inet_ntoa(addr) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment