Skip to content

Commit

Permalink
cli: add hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarrier committed Feb 6, 2025
1 parent d264fce commit 13080cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions cli/Response.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

struct Response {
std::string ip;
std::optional<std::string> hostname;
std::optional<std::string> aso;
std::optional<int> asn;
std::optional<std::string> continent;
Expand Down
20 changes: 12 additions & 8 deletions cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

inline void print_ident_data(const std::string& label, const Response& data) {
std::cout << label << " address: " << data.ip << '\n';
if (data.hostname) {
std::cout << " Hostname: " << *data.hostname << '\n';
}
if (data.aso && data.asn) {
std::cout << " AS: " << *data.aso << " (" << *data.asn << ")\n";
}
Expand Down Expand Up @@ -53,16 +56,17 @@ Response parse_ident_json(const std::string& jsonStr) {
}
};

maybe_set_string("hostname", result.hostname);
maybe_set_string("aso", result.aso);
maybe_set_int("asn", result.asn);
maybe_set_int("asn", result.asn);
maybe_set_string("continent", result.continent);
maybe_set_string("cc", result.cc);
maybe_set_string("country", result.country);
maybe_set_string("city", result.city);
maybe_set_string("postal", result.postal);
maybe_set_float("latitude", result.latitude);
maybe_set_float("longitude", result.longitude);
maybe_set_string("tz", result.tz);
maybe_set_string("cc", result.cc);
maybe_set_string("country", result.country);
maybe_set_string("city", result.city);
maybe_set_string("postal", result.postal);
maybe_set_float("latitude", result.latitude);
maybe_set_float("longitude", result.longitude);
maybe_set_string("tz", result.tz);

return result;
} catch (const nlohmann::json::parse_error& e) {
Expand Down

0 comments on commit 13080cb

Please sign in to comment.