switching ips
This commit is contained in:
parent
61ba7f4cbf
commit
fa3a9ce85b
50
index.js
50
index.js
|
@ -229,6 +229,56 @@ function mergeIt(audioPath, videoPath, outputPath) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function switchIps() {
|
||||||
|
const currentIp = await (await fetch('http://localhost:8000/v1/publicip/ip', {
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313'
|
||||||
|
}
|
||||||
|
})).json()
|
||||||
|
const currentDate = new Date()
|
||||||
|
|
||||||
|
console.log(`starting switching ips. ${currentIp.public_ip}, ${currentIp.city}, ${currentIp.region}, ${currentIp.organization}`)
|
||||||
|
|
||||||
|
const s = await fetch('http://localhost:8000/v1/vpn/status', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ status: 'stopped' })
|
||||||
|
})
|
||||||
|
console.log(`stopped vpn - ${await s.text()}`)
|
||||||
|
|
||||||
|
const r = await fetch('http://localhost:8000/v1/vpn/status', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ status: 'running' })
|
||||||
|
})
|
||||||
|
console.log(`turned on vpn - ${await r.text()}`)
|
||||||
|
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const intervalId = setInterval(async () => {
|
||||||
|
const newIp = await (await fetch('http://localhost:8000/v1/publicip/ip', {
|
||||||
|
headers: {
|
||||||
|
'X-API-Key': '64d1781e469965c1cdad611b0c05d313',
|
||||||
|
},
|
||||||
|
})).json();
|
||||||
|
|
||||||
|
if (newIp.public_ip !== '') {
|
||||||
|
console.log(`finished switching ips. ${newIp.public_ip}, ${newIp.city}, ${newIp.region}, ${newIp.organization}. took ${(new Date().getTime() - currentDate.getTime()) / 1000}s`)
|
||||||
|
clearInterval(intervalId);
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(switchIps, 30 * 60000) // 30 minutes
|
||||||
|
|
||||||
app.listen(8008, () => {
|
app.listen(8008, () => {
|
||||||
console.log('the metadata server is up.')
|
console.log('the metadata server is up.')
|
||||||
|
switchIps()
|
||||||
})
|
})
|
Loading…
Reference in New Issue