Support get global IP address
This commit is contained in:
@@ -392,6 +392,35 @@ namespace ANSCENTER
|
||||
double netSendSpeedMBs = -1.0;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Public IP + IP-based geolocation, sourced from ipapi.co/json/.
|
||||
//
|
||||
// One HTTPS GET per refresh; results cached for 60 minutes (success) or
|
||||
// 60 seconds (failure backoff). Never throws, never blocks more than 5 s.
|
||||
//
|
||||
// `ok == false` means the data could not be obtained — `error` carries
|
||||
// the reason ("HTTP 429", "WinHttpConnect failed", "JSON parse: ...",
|
||||
// etc.). Latitude/longitude are 0,0 when unknown.
|
||||
//
|
||||
// Privacy note: this performs an outbound HTTPS request to a third-party
|
||||
// service (ipapi.co). Each request reveals the device's public IP to that
|
||||
// service. Use the simpler GetPublicIPAddress() if you only need the IP
|
||||
// and prefer no third-party HTTP hop.
|
||||
// ------------------------------------------------------------------------
|
||||
struct PublicNetworkInfo {
|
||||
bool ok = false;
|
||||
std::string publicIP; // e.g. "203.0.113.42"
|
||||
std::string country; // full name, e.g. "Vietnam"
|
||||
std::string countryCode; // ISO 2-letter, e.g. "VN"
|
||||
std::string region; // state / province
|
||||
std::string city;
|
||||
std::string isp; // organization / provider name
|
||||
std::string timezone; // IANA tz, e.g. "Asia/Ho_Chi_Minh"
|
||||
double latitude = 0.0;
|
||||
double longitude = 0.0;
|
||||
std::string error; // empty on success
|
||||
};
|
||||
|
||||
|
||||
|
||||
class ANSLICENSE_API SPDLogger
|
||||
@@ -494,6 +523,24 @@ namespace ANSCENTER
|
||||
[[nodiscard]] static bool LicenseVerification(std::string licenseKey, int productId, std::string registrationName);
|
||||
[[nodiscard]] static EngineType CheckHardwareInformation();
|
||||
[[nodiscard]] static SystemHealthInfo GetSystemHealthInformation();
|
||||
|
||||
// Returns the device's public IPv4 address as seen from the internet,
|
||||
// or an empty string if it can't be resolved (no connectivity, DNS
|
||||
// blocked, etc). Result is cached for 10 minutes — subsequent calls
|
||||
// are a memory read.
|
||||
//
|
||||
// Implementation uses a single DNS query to OpenDNS's special name
|
||||
// 'myip.opendns.com' (the resolver echoes back the client's seen IP
|
||||
// in an A record). No HTTP, no third-party REST, no database — works
|
||||
// on any network where outbound DNS to 208.67.222.222 is allowed
|
||||
// (which is the vast majority, including most corporate firewalls).
|
||||
[[nodiscard]] static std::string GetPublicIPAddress();
|
||||
|
||||
// Public IP + geolocation in one shot via ipapi.co/json/. See the
|
||||
// PublicNetworkInfo doc-comment for caching, failure semantics, and
|
||||
// privacy implications. If you only need the IP, prefer the simpler
|
||||
// GetPublicIPAddress() above (no HTTP, no third-party REST).
|
||||
[[nodiscard]] static PublicNetworkInfo GetPublicNetworkInformation();
|
||||
[[nodiscard]] static std::string ListLicenses();
|
||||
[[nodiscard]] static int ActivateTrialLicense(std::string productName);
|
||||
[[nodiscard]] static int DeactivateLicense(std::string productName);
|
||||
@@ -595,6 +642,42 @@ extern "C" __declspec(dllexport) int GetSystemHealthParameters(
|
||||
// outer separator is never ambiguous.
|
||||
// Returns 1 on success, 0 on failure.
|
||||
extern "C" __declspec(dllexport) int GetSystemHealthParametersString(LStrHandle outString);
|
||||
|
||||
// Writes the device's public IPv4 (e.g. "203.0.113.42") into the LStrHandle.
|
||||
// Returns 1 on success, 0 if the IP could not be resolved. Cached for 10 min.
|
||||
extern "C" __declspec(dllexport) int GetPublicIPAddress(LStrHandle ipv4);
|
||||
|
||||
// Public IP + IP-based geolocation via ipapi.co/json/. Each pointer is
|
||||
// optional; pass nullptr to skip a field. `errorMsg` carries a human-readable
|
||||
// reason when the call fails (no internet, rate limit, etc.). Returns 1 on
|
||||
// success, 0 on failure. Cached for 1 hour on success; 1-minute back-off on
|
||||
// failure so a flapping network doesn't get hammered.
|
||||
extern "C" __declspec(dllexport) int GetPublicNetworkParameters(
|
||||
LStrHandle publicIP,
|
||||
LStrHandle country,
|
||||
LStrHandle countryCode,
|
||||
LStrHandle region,
|
||||
LStrHandle city,
|
||||
LStrHandle isp,
|
||||
LStrHandle timeZone,
|
||||
double* latitude,
|
||||
double* longitude,
|
||||
LStrHandle errorMsg);
|
||||
|
||||
// Same payload packed as a single ';'-separated string in this exact order:
|
||||
// 1 publicIP
|
||||
// 2 country (full name)
|
||||
// 3 countryCode (ISO 2-letter)
|
||||
// 4 region
|
||||
// 5 city
|
||||
// 6 isp
|
||||
// 7 timezone (IANA, e.g. "Asia/Ho_Chi_Minh")
|
||||
// 8 latitude (6dp, C locale)
|
||||
// 9 longitude (6dp, C locale)
|
||||
// Any literal ';' inside string fields is rewritten to ',' so the separator
|
||||
// stays unambiguous. Returns 1 on success, 0 on failure (string still written
|
||||
// — values just empty/0).
|
||||
extern "C" __declspec(dllexport) int GetPublicNetworkParametersString(LStrHandle outString);
|
||||
extern "C" __declspec(dllexport) int ReleaseLoggers();
|
||||
extern "C" __declspec(dllexport) int ListANSLicenses(std::string &listLicense);
|
||||
extern "C" __declspec(dllexport) int ListANSLicenses_LV(LStrHandle ansProductLicenses);
|
||||
|
||||
Reference in New Issue
Block a user