* option to force a refresh
* option to run in loop every 5 minutes * pack into deb, rpm ant targz archive
This commit is contained in:
@ -8,9 +8,13 @@
|
||||
#include <api/IPAPI.h>
|
||||
#include <api/DynuAPI.h>
|
||||
#include <api/TelegramAPI.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "IPRefresher.h"
|
||||
|
||||
void IPRefresher::checkIPAdress() {
|
||||
void IPRefresher::checkIPAdress(bool force) {
|
||||
Logger logger;
|
||||
|
||||
IPAPI ipapi;
|
||||
@ -23,7 +27,7 @@ void IPRefresher::checkIPAdress() {
|
||||
} else {
|
||||
std::string oldip = logger.readip();
|
||||
|
||||
if (oldip == ip) {
|
||||
if (oldip == ip && !force) {
|
||||
std::cout << "[INFO] no change -- ip: " << ip << std::endl;
|
||||
logger.logToLogfile(" [INFO] no change -- ip: " + ip);
|
||||
} else {
|
||||
@ -45,3 +49,14 @@ void IPRefresher::checkIPAdress() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IPRefresher::IPRefresher() {
|
||||
|
||||
}
|
||||
|
||||
IPRefresher::IPRefresher(bool loop) {
|
||||
while(true){
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(300000));
|
||||
checkIPAdress(false);
|
||||
}
|
||||
}
|
||||
|
11
src/main.cpp
11
src/main.cpp
@ -8,15 +8,24 @@ int main(int argc, char *argv[]) {
|
||||
if (firstarg == "-h" || firstarg == "--help") {
|
||||
std::cout << "help page: " << std::endl << "[-h] [--help] print this help page" << std::endl
|
||||
<< "[-v] [--version] print the software version" << std::endl
|
||||
<< "[-f] [--force] force refresh of ip" << std::endl
|
||||
<< "[-l] [--loop] infinite loop to refresh ip every five minutes" << std::endl
|
||||
<< "[no argument] normal ip check and refresh" << std::endl;
|
||||
} else if (firstarg == "-v" || firstarg == "--version") {
|
||||
std::cout << "Version 1.0" << std::endl;
|
||||
} else if (firstarg == "-f" || firstarg == "--force") {
|
||||
IPRefresher ipr;
|
||||
ipr.checkIPAdress(true);
|
||||
} else if (firstarg == "-l" || firstarg == "--loop") {
|
||||
IPRefresher ipr(true);
|
||||
ipr.checkIPAdress(false);
|
||||
} else {
|
||||
std::cout << "wrong arguments! -h for help" << std::endl;
|
||||
}
|
||||
} else {
|
||||
IPRefresher ipr;
|
||||
ipr.checkIPAdress();
|
||||
ipr.checkIPAdress(false);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user