forked from TooTallNate/node-socks-proxy-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nordvpn.ts
72 lines (62 loc) · 1.47 KB
/
nordvpn.ts
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
import https from 'https';
import fetch from 'node-fetch';
import create, { SocksProxyAgent, SocksProxyAgentOptions } from './src';
const API = 'https://nordvpn.com/api/server'
interface Proxy {
name: string;
domain: string;
ip_address: string;
features: {
socks: boolean;
};
}
async function main() {
const res = await fetch(API);
const data: Proxy[] = await res.json();
for (const proxy of data) {
await test(proxy);
}
}
async function test(proxy: Proxy) {
if (!proxy.features.socks) {
//console.log('`socks` is not supported');
return;
}
console.log('Testing %j - %s (%s)', proxy.name, proxy.domain, proxy.ip_address);
//console.log(proxy);
const info: SocksProxyAgentOptions = {
host: proxy.domain,
username: '[email protected]',
password: 'Zez]7KW8ZTEy3NaD;8&K'
};
const agent = new SocksProxyAgent(info);
try {
const { ip } = await new Promise((resolve, reject) => {
https
.get(
'https://jsonip.org',
{
agent
},
res => {
//console.log(res.headers);
let data = ''
res.setEncoding('utf8');
res.on('data', d => { data += d });
res.on('end', () => {
resolve(JSON.parse(data));
});
}
)
.once('error', reject);
});
console.log('✅ %j works! IP: %s', proxy.domain, ip);
} catch (err) {
console.log('🛑 %j does not work :( - %s', proxy.domain, err.toString().split('\n')[0]);
}
console.log();
}
main().catch(err => {
console.error(err);
process.exit(1);
});