This article explains a powerful C++ script that queries DNS records and WHOIS information for any domain.
The C++ script is designed to fetch DNS records (such as A, AAAA, MX, TXT, etc.) from multiple DNS servers and retrieve WHOIS information for a given domain. It executes the following steps:
nslookup command.To use this script, follow these steps:
g++ dns_info.cpp -o dns_info
./dns_info www.domainname.com path_to_where_you_want_to_save_results!\dns_info.txt
// Script code here (shortened for brevity)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef _WIN32
#include
#define popen _popen
#define pclose _pclose
#endif
std::string exec(const char* cmd) {
std::array buffer;
std::string result;
std::unique_ptr pipe(popen(cmd, "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
result += buffer.data();
}
return result;
}
std::vector split(const std::string& s, char delimiter) {
std::vector tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
void queryDNS(std::ofstream& outputFile, const std::string& url, const std::string& dnsServer) {
std::string dnsTypes[] = {"A", "AAAA", "MX", "TXT", "NS", "SOA", "CNAME", "PTR"};
for (const auto& type : dnsTypes) {
outputFile << "DNS " << type << " Records:" << std::endl;
std::string result = exec(("nslookup -type=" + type + " " + url + " " + dnsServer).c_str());
outputFile << result << std::endl;
// Interpret specific records
if (type == "MX") {
outputFile << "Interpretation: These are mail exchange servers for " << url << std::endl;
} else if (type == "TXT") {
if (result.find("v=spf1") != std::string::npos) {
outputFile << "Interpretation: SPF record found. This specifies which IP addresses are allowed to send email for this domain." << std::endl;
}
} else if (type == "SOA") {
outputFile << "Interpretation: This is the Start of Authority record, containing administrative information about the zone." << std::endl;
}
outputFile << std::endl;
}
}
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: " << argv[0] << "