diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 57b0aa3..e5dfa27 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,5 +1,8 @@
+
+
+
@@ -11,62 +14,13 @@
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -82,15 +36,6 @@
-
-
-
-
-
-
-
-
-
@@ -106,8 +51,8 @@
-
-
+
+
@@ -117,11 +62,11 @@
-
+
-
-
+
+
@@ -129,11 +74,47 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -150,9 +131,11 @@
-
-
+
+
+
+
@@ -174,6 +157,11 @@
+
+
+
+
+
@@ -234,7 +222,7 @@
-
+
1557063528491
@@ -243,11 +231,25 @@
1557063528491
-
+
+ 1557063846200
+
+
+
+ 1557063846200
+
+
+ 1557063931807
+
+
+
+ 1557063931807
+
+
-
+
@@ -258,13 +260,13 @@
-
+
-
+
@@ -280,7 +282,8 @@
-
+
+
@@ -307,29 +310,62 @@
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ad193d8..2fdecfa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -7,7 +7,7 @@ find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIR})
-set(SOURCE src/main.cpp src/API.h src/API.cpp src/Hashmap.h)
+set(SOURCE src/main.cpp src/API.h src/API.cpp src/Hashmap.h src/Logger.cpp src/Logger.h)
add_executable(iprefresher ${SOURCE})
diff --git a/src/API.cpp b/src/API.cpp
index ab6bbc5..88061fb 100644
--- a/src/API.cpp
+++ b/src/API.cpp
@@ -43,7 +43,6 @@ std::string API::request(std::string myurl, bool post, Hashmap
+#include
+#include
+#include
+
+#include "Logger.h"
+
+void Logger::safeip(std::string ip) {
+ std::ofstream out;
+ out.open("ip.txt",std::ios::out);
+
+ out << ip;
+
+ out.close();
+}
+
+std::string Logger::readip() {
+ std::ifstream in;
+ in.open("ip.txt",std::ios::in);
+
+ std::string ip;
+
+ in >> ip;
+
+ return ip;
+}
+
+void Logger::logToLogfile(std::string text) {
+ std::ofstream out;
+ out.open("dynurefresher.log",std::ios::out | std::ios::app);
+
+
+ std::time_t t = std::time(0); // get time now
+ std::tm* now = std::localtime(&t);
+
+ std::stringstream logline;
+
+ logline << "[ "<< (now->tm_year + 1900) << '-' << (now->tm_mon + 1) << '-' << now->tm_mday
+ << "_" << now->tm_hour << ":" << now->tm_min << ":" << now->tm_sec << " ] " << '\t' << text << std::endl;
+
+
+ out << logline.str();
+
+ out.close();
+}
diff --git a/src/Logger.h b/src/Logger.h
new file mode 100644
index 0000000..efcb2b1
--- /dev/null
+++ b/src/Logger.h
@@ -0,0 +1,18 @@
+//
+// Created by lukas on 05.05.19.
+//
+
+#ifndef IPREFRESHER_LOGGER_H
+#define IPREFRESHER_LOGGER_H
+
+
+class Logger {
+public:
+ void logToLogfile(std::string text);
+ void safeip(std::string ip);
+ std::string readip();
+
+};
+
+
+#endif //IPREFRESHER_LOGGER_H
diff --git a/src/main.cpp b/src/main.cpp
index bd820dc..ff36869 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,28 +1,44 @@
#include
+#include
#include "API.h"
+#include "Logger.h"
int main() {
- std::cout << "Hello, World!" << std::endl;
-
API api;
+ Logger logger;
+
+
std::string ip = api.request("https://api.ipify.org");
- std::cout << ip < args;
+ 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;
- args.add("name","luki.dynu.net");
- args.add("ipv4Address",ip);
+ //api key: 88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg
- std::vector 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");
+ Hashmap args;
- std::string dynurepl = api.request("https://api.dynu.com/v2/dns/8506047",true, args,headers);
+ args.add("name","luki.dynu.net");
+ args.add("ipv4Address",ip);
+
+ std::vector 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::string dynurepl = api.request("https://api.dynu.com/v2/dns/8506047",true, args,headers);
+
+ std::cout << "---" << dynurepl << std::endl;
+
+ logger.safeip(ip);
+ }
- std::cout << "---" << dynurepl << "\n";
return 0;