added internet connection detection

This commit is contained in:
2019-05-05 18:50:10 +02:00
parent 97469e3e43
commit 004ca7c62c
4 changed files with 123 additions and 92 deletions

View File

@ -7,8 +7,7 @@
#include <string>
#include <iostream>
#include <stdio.h>
#include <curl/curl.h>
#include "curl/curl.h"
#include <sstream>
#include "Hashmap.h"

View File

@ -11,39 +11,44 @@ int main() {
std::string ip = api.request("https://api.ipify.org");
std::string oldip = logger.readip();
if(ip == ""){
//no internet connection
logger.logToLogfile("[WARNING] no internet connection");
std::cout << "[WARNING] no internet connection" << std::endl;
if(oldip == ip){
std::cout << "no change -- ip: " << ip << std::endl;
logger.logToLogfile("no change -- ip: "+ip);
} else{
logger.logToLogfile("ip changed! -- from :" + oldip + "to: "+ip);
std::cout << "ip changed! -- from :" << oldip << "to: " << ip << std::endl;
}else{
std::string oldip = logger.readip();
//api key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg
if(oldip == ip){
std::cout << "no change -- ip: " << ip << std::endl;
logger.logToLogfile("no change -- ip: "+ip);
} else{
logger.logToLogfile("ip changed! -- from :" + oldip + "to: "+ip);
std::cout << "ip changed! -- from :" << oldip << "to: " << ip << std::endl;
Hashmap<std::string, std::string> args;
//api key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg
args.add("name","luki.dynu.net");
args.add("ipv4Address",ip);
Hashmap<std::string, std::string> args;
std::vector<std::string> headers;
headers.push_back("accept: application/json");
headers.push_back("User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)");
headers.push_back("API-Key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg");
args.add("name","luki.dynu.net");
args.add("ipv4Address",ip);
std::string dynurepl = api.request("https://api.dynu.com/v2/dns/8506047",true, args,headers);
std::vector<std::string> headers;
headers.push_back("accept: application/json");
headers.push_back("User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)");
headers.push_back("API-Key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg");
std::cout << "---" << dynurepl << std::endl;
std::string dynurepl = api.request("https://api.dynu.com/v2/dns/8506047",true, args,headers);
if (dynurepl != "{\"statusCode\":200}"){
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
std::cout << "---" << dynurepl << std::endl;
if (dynurepl != "{\"statusCode\":200}"){
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
}
logger.safeip(ip);
}
logger.safeip(ip);
}
return 0;
}