DynuIPRefresher/src/main.cpp

54 lines
1.6 KiB
C++
Raw Normal View History

2019-05-05 13:38:48 +00:00
#include <iostream>
2019-05-05 14:35:38 +00:00
#include <ctime>
2019-05-05 14:42:39 +00:00
2019-05-05 13:38:48 +00:00
#include "API.h"
2019-05-05 14:35:38 +00:00
#include "Logger.h"
2019-05-05 13:38:48 +00:00
int main() {
API api;
2019-05-05 14:35:38 +00:00
Logger logger;
2019-05-05 13:38:48 +00:00
std::string ip = api.request("https://api.ipify.org");
2019-05-05 14:35:38 +00:00
2019-05-05 16:50:10 +00:00
if(ip == ""){
//no internet connection
logger.logToLogfile("[WARNING] no internet connection");
std::cout << "[WARNING] no internet connection" << std::endl;
2019-05-05 14:35:38 +00:00
2019-05-05 16:50:10 +00:00
}else{
std::string oldip = logger.readip();
2019-05-05 14:35:38 +00:00
2019-05-05 16:50:10 +00:00
if(oldip == ip){
std::cout << "no change -- ip: " << ip << std::endl;
2019-05-05 18:23:31 +00:00
logger.logToLogfile(" [INFO] no change -- ip: "+ip);
2019-05-05 16:50:10 +00:00
} else{
2019-05-05 18:23:31 +00:00
logger.logToLogfile(" [INFO] ip changed! -- from :" + oldip + "to: "+ip);
2019-05-05 16:50:10 +00:00
std::cout << "ip changed! -- from :" << oldip << "to: " << ip << std::endl;
2019-05-05 14:35:38 +00:00
2019-05-05 16:50:10 +00:00
//api key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg
2019-05-05 13:38:48 +00:00
2019-05-05 16:50:10 +00:00
Hashmap<std::string, std::string> args;
2019-05-05 13:38:48 +00:00
2019-05-05 16:50:10 +00:00
args.add("name","luki.dynu.net");
args.add("ipv4Address",ip);
2019-05-05 13:38:48 +00:00
2019-05-05 16:50:10 +00:00
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");
2019-05-05 13:38:48 +00:00
2019-05-05 16:50:10 +00:00
std::string dynurepl = api.request("https://api.dynu.com/v2/dns/8506047",true, args,headers);
2019-05-05 13:38:48 +00:00
2019-05-05 18:23:31 +00:00
std::cout << "[ DEBUG ] api reply:: " << dynurepl << std::endl;
2019-05-05 13:38:48 +00:00
2019-05-05 16:50:10 +00:00
if (dynurepl != "{\"statusCode\":200}"){
logger.logToLogfile(" [ERROR] failed to write ip to dynu api!");
}
2019-05-05 13:38:48 +00:00
2019-05-05 16:50:10 +00:00
logger.safeip(ip);
}
}
2019-05-05 13:38:48 +00:00
return 0;
}