@@ -26,14 +26,46 @@ void trim(std::string &);
2626struct json_data_t {
2727 std::string domain_name{};
2828 std::string rdata{};
29+ std::string first_seen{};
30+ std::string last_seen{};
2931 int ttl{};
3032 int http_code{};
3133 int content_length{};
34+ int seen{};
35+ bool currently_seen{true };
3236 dns_record_type_e type{};
3337
3438 static json_data_t serialize (std::string const &d, int const len,
3539 int const http_code,
3640 json::object_t &json_object) {
41+ auto const string_value = [&json_object](char const *first_key,
42+ char const *second_key) {
43+ auto first_iter = json_object.find (first_key);
44+ if (first_iter != json_object.end () && first_iter->second .is_string ()) {
45+ return first_iter->second .get <json::string_t >();
46+ }
47+ auto second_iter = json_object.find (second_key);
48+ if (second_iter != json_object.end () && second_iter->second .is_string ()) {
49+ return second_iter->second .get <json::string_t >();
50+ }
51+ return json::string_t {};
52+ };
53+ auto const int_value = [&json_object](char const *key, int const fallback) {
54+ auto iter = json_object.find (key);
55+ if (iter != json_object.end () && iter->second .is_number_integer ()) {
56+ return static_cast <int >(iter->second .get <json::number_integer_t >());
57+ }
58+ return fallback;
59+ };
60+ auto const bool_value = [&json_object](char const *key,
61+ bool const fallback) {
62+ auto iter = json_object.find (key);
63+ if (iter != json_object.end () && iter->second .is_boolean ()) {
64+ return iter->second .get <json::boolean_t >();
65+ }
66+ return fallback;
67+ };
68+
3769 json_data_t data{};
3870 data.domain_name = d;
3971 data.type =
@@ -42,6 +74,10 @@ struct json_data_t {
4274 data.ttl = json_object[" ttl" ].get <json::number_integer_t >();
4375 data.content_length = len;
4476 data.http_code = http_code;
77+ data.first_seen = string_value (" first-seen" , " first_seen" );
78+ data.last_seen = string_value (" last-seen" , " last_seen" );
79+ data.seen = int_value (" seen" , data.last_seen .empty () ? 0 : 1 );
80+ data.currently_seen = bool_value (" currently_seen" , true );
4581 return data;
4682 }
4783};
@@ -82,6 +118,7 @@ void write_json_result_impl(map_container_t<DnsType> const &result_map,
82118 json::object_t res_object;
83119
84120 res_object[" program" ] = " dooked" ;
121+ res_object[" scanned_at" ] = rt_args.scan_time ;
85122 res_object[" result" ] = std::move (list);
86123 (*rt_args.output_file ) << json (res_object).dump (2 ) << " \n " ;
87124 rt_args.output_file ->close ();
0 commit comments