#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] << " " << std::endl; return 1; } std::string url = argv[1]; std::string filePath = argv[2]; std::ofstream outputFile(filePath); if (!outputFile.is_open()) { std::cerr << "Failed to create output file at: " << filePath << std::endl; return 1; } // Query to multiple DNS servers std::vector dnsServers = {"8.8.8.8", "1.1.1.1", "9.9.9.9"}; for (const auto& server : dnsServers) { outputFile << "Results from DNS server " << server << ":" << std::endl; queryDNS(outputFile, url, server); outputFile << std::endl << "--------------------------------" << std::endl << std::endl; } // Attempt to get WHOIS information outputFile << "WHOIS Information:" << std::endl; outputFile << exec(("whois " + url).c_str()) << std::endl; outputFile.close(); std::cout << "DNS and domain information saved to " << filePath << std::endl; return 0; }