-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
47 lines (41 loc) · 1.58 KB
/
Copy pathmain.cpp
File metadata and controls
47 lines (41 loc) · 1.58 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
#include <string.h>
#include <iostream>
#include <algorithm>
#include <wsjcpp_core.h>
#include <wsjcpp_geoip.h>
int main(int argc, const char* argv[]) {
std::string TAG = "MAIN";
std::string appName = std::string(WSJCPP_APP_NAME);
std::string appVersion = std::string(WSJCPP_APP_VERSION);
if (!WsjcppCore::dirExists(".wsjcpp")) {
WsjcppCore::makeDir(".wsjcpp");
}
std::string appLogPath = ".wsjcpp/logs";
if (!WsjcppCore::dirExists(appLogPath)) {
WsjcppCore::makeDir(appLogPath);
}
WsjcppLog::setPrefixLogFile("wsjcpp");
WsjcppLog::setLogDirectory(".wsjcpp/logs");
std::vector<std::string> vArgs;
for (int i = 0; i < argc; i++) {
vArgs.push_back(std::string(argv[i]));
}
if (vArgs.size() != 2) {
std::cout << "Usage: " << vArgs[0] << " <ip-adderss>" << std::endl;
return -1;
}
std::string sIpAddress = vArgs[1];
WsjcppGeoIPResult res = WsjcppGeoIP::requestToIpApiCom(sIpAddress);
if (res.hasError()) {
std::cout << "FAILED: " << res.getErrorDescription() << std::endl;
} else {
std::cout << "Service Name: " << res.getServiceName() << std::endl;
std::cout << "IP Address: " << res.getIpAddress() << std::endl;
std::cout << "Country: " << res.getCountry() << std::endl;
std::cout << "Region Name: " << res.getRegionName() << std::endl;
std::cout << "City: " << res.getCity() << std::endl;
std::cout << "Latitude: " << res.getLatitude() << std::endl;
std::cout << "Longitude: " << res.getLongitude() << std::endl;
}
return 0;
}