-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ip lookup functionality for fun... just yet another module!
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _IPLOOKUP_H | ||
#define _IPLOOKUP_H | ||
|
||
#include "./json.hpp" | ||
|
||
namespace IPLookup { | ||
|
||
std::string do_lookup(const std::string& host); | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "./include/iplookup.hpp" | ||
#include "./include/json.hpp" | ||
#include "./include/http.hpp" | ||
|
||
namespace IPLookup { | ||
|
||
static void do_lookup_internal(const std::string& host, nlohmann::json& result) { | ||
std::string response = ""; | ||
MyHTTP::get("http://freegeoip.net/json/" + host, response); | ||
result = nlohmann::json::parse(response); | ||
} | ||
|
||
std::string do_lookup(const std::string& host) { | ||
|
||
nlohmann::json result; | ||
do_lookup_internal(host,result); | ||
|
||
return "Location: " + result["city"].get<std::string>() + ", " + result["region_code"].get<std::string>() + ", " | ||
+ result["country_name"].get<std::string>(); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters