質問編集履歴
1
ソースコードの追加
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -7,6 +7,47 @@
|
|
|
7
7
|
プロキシに関してはまだまだ未熟なのでそこも含めて詳しく回答して頂けると幸いです。
|
|
8
8
|
よろしくお願いします。
|
|
9
9
|
|
|
10
|
+
ソースコード
|
|
11
|
+
```
|
|
12
|
+
// *** モジュールのインクルード *** //
|
|
13
|
+
const proxyAgent = require('proxy-agent');
|
|
14
|
+
const request = require('request');
|
|
15
|
+
const WebSocket = require('ws');
|
|
16
|
+
|
|
17
|
+
// *** プロキシの設定 *** //
|
|
18
|
+
let allProxyAgents = [];
|
|
19
|
+
let proxyAgents = [];
|
|
20
|
+
function getProxy() {
|
|
21
|
+
if (proxyAgents.length == 0) {
|
|
22
|
+
proxyAgents = allProxyAgents;
|
|
23
|
+
}
|
|
24
|
+
return proxyAgents.shift();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// *** プロキシの一覧を取得 *** //
|
|
28
|
+
function getProxys() {
|
|
29
|
+
console.log(`プロキシの一覧を取得中...`);
|
|
30
|
+
request('https://www.proxy-list.download/api/v1/get?type=socks5', (err, req, body) => {
|
|
31
|
+
let proxies = body.replace(/\r/g, '').split('\n');
|
|
32
|
+
proxies.forEach(proxy => {
|
|
33
|
+
allProxyAgents.push(new proxyAgent(`socks://${proxy}`));
|
|
34
|
+
});
|
|
35
|
+
console.log(`${proxies.length}個のプロキシが接続可能です。`);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// *** 接続 *** //
|
|
40
|
+
console.log('接続中...');
|
|
41
|
+
ws = new WebSocket(/*URL?*/, {
|
|
42
|
+
origin: /*???*/,
|
|
43
|
+
rejectUnauthorized: false,
|
|
44
|
+
agent: getProxy()
|
|
45
|
+
});
|
|
46
|
+
ws.on('close', function () {
|
|
47
|
+
console.error('終了しました。');
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
10
51
|
追記:
|
|
11
52
|
スマホからの入力なので文章が見にくいかもしれません。
|
|
12
53
|
すいません。
|