-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (28 loc) · 831 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const axios = require('axios');
const fs = require('fs');
const settings = require('./settings.json');
console.log(settings);
console.log('Script started');
let theIP;
function getIP(){
return axios.get('https://api.ipify.org?format=json')
.then(res => res.data.ip);
}
theIP = JSON.parse(fs.readFileSync(settings.outputFile || './ip.json')).ip;
setInterval(() => {
getIP().then(ip => {
console.log(ip);
if(ip !== theIP){
axios.post(settings.endpoint, {
ip: ip
})
.then(res => {
console.log('changed');
theIP = ip;
fs.writeFileSync(settings.outputFile || './ip.json', '{"ip": "' + theIP + '"}');
});
} else {
console.log('hasn\'t changed');
};
});
}, settings.interval || (86400000 / 2));