added internet connection detection
This commit is contained in:
@ -7,8 +7,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <curl/curl.h>
|
||||
#include "curl/curl.h"
|
||||
#include <sstream>
|
||||
|
||||
#include "Hashmap.h"
|
||||
|
51
src/main.cpp
51
src/main.cpp
@ -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;
|
||||
}
|
Reference in New Issue
Block a user