Untitled
Anonymous
plain_text
08/16/2023 10:39 AM
668 B
22
Indexable
std::string func::GetIP()
{
std::string ipAddress = "";
CURL* curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://api.ipify.org");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, func::WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ipAddress);
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
return "Failed to retrieve IP address: " + std::string(curl_easy_strerror(res));
}
curl_easy_cleanup(curl);
}
return ipAddress;
}Editor is loading...