This repository has been archived by the owner on Feb 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnord.js
80 lines (72 loc) · 2.23 KB
/
nord.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const fs = require('fs')
const execa = require('execa')
const chalk = require('chalk')
let ip = []
let ipPass = 0
let s = { //settings
pingTimeout: 1,
pingAmount: 1 // 'all' or amount
}
let serverList = fs.readdirSync('/etc/openvpn/ovpn_tcp/')
serverList.forEach(function(item, i) {
serverList[i] = '/etc/openvpn/ovpn_tcp/' + item
})
//Parsing fales
for (let i = 0; i < serverList.length; i++) {
let data = fs.readFileSync(serverList[i]).toString()
serverList[i] = serverList[i].split('/').slice(4).toString().split('.').slice(0, 1).toString() // '/etc/openvpn/ovpn_tcp/uk951.nordvpn.com.tcp.ovpn' => 'uk951'
data = data.split('\n', 4)
data = data[3].substring(7)
let port = data.indexOf(' 443');
data = data.slice(0, port)
ip.splice(0, 0, data)
}
console.log('Have ' + ip.length + ' servers')
if (s.pingAmount != 'all' && typeof s.pingAmount != 'string') {
if (s.pingAmount > ip.length) {
console.error('You set wrong')
process.exit()
} else {
ip.splice(s.pingAmount)
console.log('Now ' + ip.length + ' servers');
}
}
// Loading
const _cliProgress = require('cli-progress')
const cliCursor = require('cli-cursor');
const bar = new _cliProgress.Bar({
fps: 60,
format: 'Cheking servers {bar} {percentage}% | {value}/{total} {server}'
}, _cliProgress.Presets.shades_classic)
bar.start(ip.length, 0)
cliCursor.hide()
//Check ip's
let passServers = 0
for (let i = 0; i < ip.length; i++) {
(async () => {
try {
// console.log('Cheking ' + ip[i])
// if (i % 2 == 0) {
bar.increment(1, {
server: serverList[i]
})
if (i == ip.length - 1) {
bar.update(ip.length, {
server: `Collect the folowing data, (~${s.pingTimeout} sec)`
})
}
// }
await execa.shell('ping -c 1 -W ' + s.pingTimeout + ' ' + ip[i])
// console.log(chalk.green('Ping pass ') + ip[i] + ' ' + serverList[i])
passServers++
} catch (e) // console.log(serverList[i] + chalk.red(' no ping'))
if (ip.length - 1 == i) {
bar.update(ip.length, {
server: chalk.green(' Done'),
})
bar.stop()
console.log('Total working servers ' + chalk.green(passServers))
console.log('Total not working servers ' + chalk.red(ip.length))
}
})()
}