fhq-server  v0.2.33
Documentation for fhq-server. FreeHackQuest is an open source platform for competitions of computer security.
wsjcpp_geoip.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef WSJCPP_GEOIP_H
3 #define WSJCPP_GEOIP_H
4 
5 #include <string>
6 #include <json.hpp>
7 
9  public:
10  // ok
12  const std::string &sServiceName,
13  const std::string &sIpAddress,
14  const std::string &sCountry,
15  const std::string &sRegionName,
16  const std::string &sCity,
17  double nLatitude,
18  double nLongitude
19  );
20  // error
22  const std::string &sServiceName,
23  const std::string &sIpAddress,
24  const std::string &sErrorDescription
25  );
26  bool hasError();
27  std::string getServiceName();
28  std::string getIpAddress();
29  std::string getErrorDescription();
30  std::string getCountry();
31  std::string getRegionName();
32  std::string getCity();
33  double getLatitude();
34  double getLongitude();
35  nlohmann::json toJson();
36 
37  private:
38  std::string TAG;
40  std::string m_sServiceName;
41  std::string m_sIpAddress;
42  std::string m_sErrorDescription;
43  std::string m_sCountry;
44  std::string m_sRegionName;
45  std::string m_sCity;
46  double m_nLatitude;
47  double m_nLongitude;
48 };
49 
50 // ---------------------------------------------------------------------
51 
53  public:
54  WsjcppGeoIPv4();
55  WsjcppGeoIPv4(const unsigned char arrIpLeft[4]);
56  WsjcppGeoIPv4(unsigned char c1, unsigned char c2, unsigned char c3, unsigned char c4);
57  bool fromString(const std::string &sIpAddress);
58  std::string toString();
59  bool operator==(const WsjcppGeoIPv4& rhs);
60  bool operator<(const WsjcppGeoIPv4& rhs);
61  bool operator>(const WsjcppGeoIPv4& rhs);
62  bool operator<=(const WsjcppGeoIPv4& rhs);
63  bool operator>=(const WsjcppGeoIPv4& rhs);
64  private:
65  unsigned char m_arrIP[4];
66 };
67 
68 // ---------------------------------------------------------------------
69 
70 class WsjcppGeoIP {
71  public:
72  static WsjcppGeoIPResult requestToIpApiCom(const std::string &sIpAddress);
73  static WsjcppGeoIPResult parseResponseIpApiCom(const std::string &sIpAddress, const std::string &sJson);
74  static bool isIPv4InReservedRange(const WsjcppGeoIPv4& ipV4, std::string &sError);
75 };
76 
77 // ---------------------------------------------------------------------
78 
79 #endif // WSJCPP_GEOIP_H
double getLatitude()
Definition: wsjcpp_geoip.cpp:105
std::string m_sErrorDescription
Definition: wsjcpp_geoip.h:42
bool m_bHasError
Definition: wsjcpp_geoip.h:39
std::string m_sIpAddress
Definition: wsjcpp_geoip.h:41
std::string m_sRegionName
Definition: wsjcpp_geoip.h:44
std::string TAG
Definition: wsjcpp_geoip.h:38
double m_nLatitude
Definition: wsjcpp_geoip.h:46
double getLongitude()
Definition: wsjcpp_geoip.cpp:114
std::string getIpAddress()
Definition: wsjcpp_geoip.cpp:63
std::string m_sServiceName
Definition: wsjcpp_geoip.h:40
std::string getCity()
Definition: wsjcpp_geoip.cpp:96
Definition: wsjcpp_geoip.h:8
bool hasError()
Definition: wsjcpp_geoip.cpp:51
std::string getRegionName()
Definition: wsjcpp_geoip.cpp:87
Definition: wsjcpp_geoip.h:70
double m_nLongitude
Definition: wsjcpp_geoip.h:47
std::string m_sCity
Definition: wsjcpp_geoip.h:45
WsjcppGeoIPResult(const std::string &sServiceName, const std::string &sIpAddress, const std::string &sCountry, const std::string &sRegionName, const std::string &sCity, double nLatitude, double nLongitude)
Definition: wsjcpp_geoip.cpp:9
nlohmann::json toJson()
Definition: wsjcpp_geoip.cpp:123
std::string getServiceName()
Definition: wsjcpp_geoip.cpp:57
std::string getErrorDescription()
Definition: wsjcpp_geoip.cpp:69
std::string m_sCountry
Definition: wsjcpp_geoip.h:43
Definition: wsjcpp_geoip.h:52
std::string getCountry()
Definition: wsjcpp_geoip.cpp:78