fix: Get client public IP return a IPV6
This commit is contained in:
@@ -326,15 +326,12 @@ LOGIN_INFOR GetLoginInfo(DWORD dwSpeed, const CONNECT_ADDRESS& conn)
|
|||||||
std::string loc = cfg.GetStr("settings", "location", "");
|
std::string loc = cfg.GetStr("settings", "location", "");
|
||||||
std::string pubIP = cfg.GetStr("settings", "public_ip", "");
|
std::string pubIP = cfg.GetStr("settings", "public_ip", "");
|
||||||
auto ip_time = cfg.GetInt("settings", "ip_time");
|
auto ip_time = cfg.GetInt("settings", "ip_time");
|
||||||
|
bool timeout = ip_time <= 0 || (time(0) - ip_time > 7 * 86400);
|
||||||
IPConverter cvt;
|
IPConverter cvt;
|
||||||
if (loc.empty()) {
|
if (loc.empty() || pubIP.empty() || timeout) {
|
||||||
std::string ip = cvt.getPublicIP();
|
pubIP = cvt.getPublicIP();
|
||||||
if (pubIP.empty()) pubIP = ip;
|
|
||||||
loc = cvt.GetGeoLocation(pubIP);
|
loc = cvt.GetGeoLocation(pubIP);
|
||||||
cfg.SetStr("settings", "location", loc);
|
cfg.SetStr("settings", "location", loc);
|
||||||
}
|
|
||||||
if ( pubIP.empty() || ip_time <= 0 || (time(0)-ip_time>7*86400) ) {
|
|
||||||
pubIP = cvt.getPublicIP();
|
|
||||||
cfg.SetStr("settings", "public_ip", pubIP);
|
cfg.SetStr("settings", "public_ip", pubIP);
|
||||||
cfg.SetInt("settings", "ip_time", time(0));
|
cfg.SetInt("settings", "ip_time", time(0));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ public:
|
|||||||
hInternet = InternetOpen("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
|
hInternet = InternetOpen("Mozilla/5.0", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
|
||||||
if (!hInternet) return "";
|
if (!hInternet) return "";
|
||||||
|
|
||||||
hConnect = InternetOpenUrl(hInternet, "https://api64.ipify.org", NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_SECURE, 0);
|
hConnect = InternetOpenUrl(hInternet, "https://api.ipify.org", NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_SECURE, 0);
|
||||||
if (!hConnect) {
|
if (!hConnect) {
|
||||||
InternetCloseHandle(hInternet);
|
InternetCloseHandle(hInternet);
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
Reference in New Issue
Block a user