-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
129 lines (100 loc) · 3.59 KB
/
main.cpp
File metadata and controls
129 lines (100 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<stdio.h>
#include <iostream>
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include <fstream>
using namespace std;
using json = nlohmann::json;
using namespace std;
void help() {
cout << "Usage: \n\n ./reverseip -u google.com -a <apikey> -o <output.txt>" << endl;
}
size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
size_t total_size = size * nmemb;
((std::string*)userp)->append((char*)contents, total_size); // Veriyi string'e ekle
return total_size;
}
vector<string> process_json_response(const string& json_data) {
vector<string> domain_list;
try {
json response = json::parse(json_data);
// API yanıtında "response" anahtarını kontrol et
if (response.contains("response") && response["response"].contains("domains")) {
json domains = response["response"]["domains"];
cout << "Found domains:" << endl;
for (const auto& domain : domains) {
string name = domain.value("name", "N/A");
cout << name << endl;
domain_list.push_back(name); // Listeye ekle
}
} else {
cerr << "Invalid JSON response: missing 'response' or 'domains' key!" << endl;
}
} catch (const json::parse_error& e) {
cerr << "JSON parse error: " << e.what() << endl;
}
return domain_list;
}
// Dosyaya kayıt fonksiyonu
void save_file(const vector<string>& domains, const string& filename) {
ofstream file(filename);
if (!file) {
cerr << "Dosya açılamadı: " << filename << endl;
return;
}
for (const auto& domain : domains) {
file << domain << endl;
}
file.close();
cout << "Data saved to '" << filename << "' successfully." << endl;
}
int main(int argc, char* argv[]){
if(argc < 6){
help();
return 1;
}
string parameter = argv[1];
string output_file = argv[6]; // Çıktı dosyası
string apikey = argv[4];
if (parameter == "-u" || parameter == "--url"){
if(argc < 6){
help();
return 1;
}
CURL* curl;
CURLcode res;
std::string read_buffer;
// cURL başlat
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
string url = "https://api.viewdns.info/reverseip/?host=" + std::string(argv[2]) + "&apikey="+std::string(apikey)+"&output=json";
//cout << url << endl;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
// Yanıtın bir string'e yazılması için callback fonksiyonunu ayarla
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &read_buffer);
// GET isteği gönder
res = curl_easy_perform(curl);
if(res == CURLE_OK) {
//process_json_response(read_buffer);
vector<string> domains = process_json_response(read_buffer);
if (!domains.empty()) {
save_file(domains, output_file); // Kaydet
} else {
cerr << "No domains found, skipping file save." << endl;
}
} else {
std::cerr << "cURL hatası: " << curl_easy_strerror(res) << std::endl;
}
// CURL kaynaklarını serbest bırak
curl_easy_cleanup(curl);
}else{
cout << "ERROR" << endl;
}
curl_global_cleanup();
}else{
help();
}
return 0;
}