w-ipproxy 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +18 -17
- package/.github/workflows/ci-test.yml +3 -3
- package/README.md +64 -2
- package/babel.config.js +4 -2
- package/dist/w-ip-proxy.umd.js +7 -0
- package/dist/w-ip-proxy.umd.js.map +1 -0
- package/docs/WIpProxy.html +722 -0
- package/docs/WIpProxy.mjs.html +554 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
- package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
- package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
- package/docs/index.html +84 -0
- package/docs/scripts/collapse.js +39 -0
- package/docs/scripts/commonNav.js +28 -0
- package/docs/scripts/linenumber.js +25 -0
- package/docs/scripts/nav.js +12 -0
- package/docs/scripts/polyfill.js +4 -0
- package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/scripts/prettify/lang-css.js +2 -0
- package/docs/scripts/prettify/prettify.js +28 -0
- package/docs/scripts/search.js +99 -0
- package/docs/styles/jsdoc.css +776 -0
- package/docs/styles/prettify.css +80 -0
- package/g-getByTimer.mjs +24 -0
- package/g-getOnce.mjs +11 -0
- package/g-srv.mjs +28 -0
- package/package.json +11 -9
- package/script.txt +17 -0
- package/src/WIpProxy.mjs +473 -14
- package/src/provideServer.mjs +65 -0
- package/test/anonymity.test.mjs +140 -0
- package/test/getProxiesOnce.test.mjs +89 -0
- package/toolg/cleanFolder.mjs +4 -0
- package/toolg/gDistRollup.mjs +29 -0
- package/toolg/modifyReadme.mjs +4 -0
- package/g.mjs +0 -12
- package/src/getHtml.mjs +0 -84
- package/src/getProxyListOrg.mjs +0 -66
- package/src/parseHtml.mjs +0 -19
- package/test/all.test.mjs +0 -10
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<title>WIpProxy.mjs - Documentation</title>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
<script src="scripts/prettify/prettify.js"></script>
|
|
10
|
+
<script src="scripts/prettify/lang-css.js"></script>
|
|
11
|
+
<!--[if lt IE 9]>
|
|
12
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
13
|
+
<![endif]-->
|
|
14
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
|
|
15
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
|
|
16
|
+
<script src="scripts/nav.js" defer></script>
|
|
17
|
+
|
|
18
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
|
|
22
|
+
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
|
|
23
|
+
<label for="nav-trigger" class="navicon-button x">
|
|
24
|
+
<div class="navicon"></div>
|
|
25
|
+
</label>
|
|
26
|
+
|
|
27
|
+
<label for="nav-trigger" class="overlay"></label>
|
|
28
|
+
|
|
29
|
+
<nav >
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="WIpProxy.html">WIpProxy</a></li></ul>
|
|
33
|
+
|
|
34
|
+
</nav>
|
|
35
|
+
|
|
36
|
+
<div id="main">
|
|
37
|
+
|
|
38
|
+
<h1 class="page-title">WIpProxy.mjs</h1>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<section>
|
|
47
|
+
<article>
|
|
48
|
+
<pre class="prettyprint source linenums"><code>import axios from 'axios'
|
|
49
|
+
import https from 'https'
|
|
50
|
+
import get from 'lodash-es/get.js'
|
|
51
|
+
import size from 'lodash-es/size.js'
|
|
52
|
+
import each from 'lodash-es/each.js'
|
|
53
|
+
import map from 'lodash-es/map.js'
|
|
54
|
+
import trim from 'lodash-es/trim.js'
|
|
55
|
+
import values from 'lodash-es/values.js'
|
|
56
|
+
import evem from 'wsemi/src/evem.mjs'
|
|
57
|
+
import sep from 'wsemi/src/sep.mjs'
|
|
58
|
+
import isestr from 'wsemi/src/isestr.mjs'
|
|
59
|
+
import ispint from 'wsemi/src/ispint.mjs'
|
|
60
|
+
import isbol from 'wsemi/src/isbol.mjs'
|
|
61
|
+
import isearr from 'wsemi/src/isearr.mjs'
|
|
62
|
+
import iseobj from 'wsemi/src/iseobj.mjs'
|
|
63
|
+
import cint from 'wsemi/src/cint.mjs'
|
|
64
|
+
import waitFun from 'wsemi/src/waitFun.mjs'
|
|
65
|
+
import provideServer from './provideServer.mjs'
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 抓取代理伺服器
|
|
70
|
+
*
|
|
71
|
+
* @class
|
|
72
|
+
* @param {Object} [opt={}] 輸入設定物件,預設{}
|
|
73
|
+
* @param {String} [opt.src='https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=5000&anonymity=all'] 輸入取得代理伺服器API字串,預設'https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=5000&anonymity=all'
|
|
74
|
+
* @param {String} [opt.tar='https://httpbin.org/ip'] 輸入檢測目標網址字串,預設'https://httpbin.org/ip'
|
|
75
|
+
* @param {Integer} [opt.timeGetProxies=30*1000] 輸入輪循抓取代理伺服器時間間隔整數,單位ms,預設30*1000
|
|
76
|
+
* @param {Integer} [opt.timeTestProxies=60*1000] 輸入輪循測試代理伺服器時間間隔整數,單位ms,預設60*1000
|
|
77
|
+
* @param {Boolean} [opt.anonymityCheck=true] 輸入是否對代理做匿名性檢測布林值,開啟時會先打https://httpbin.org/ip驗證代理不會將本機真實IP透過X-Forwarded-For等方式洩漏給目標端,預設true
|
|
78
|
+
* @param {Integer} [opt.anonymityCheckRepeats=2] 輸入匿名性檢測重複次數整數,用以偵測負載平衡型代理的機率性洩漏,任一次洩漏即判定失敗,預設2
|
|
79
|
+
* @param {Boolean} [opt.withServer=false] 輸入是否創建供數據供給伺服器布林值,預設false
|
|
80
|
+
* @param {Integer} [opt.serverPort=8080] 輸入創建伺服器所用port整數,預設8080
|
|
81
|
+
* @param {String} [opt.serverApiName='getProxies'] 輸入供給數據API名稱字串,預設'getProxies'
|
|
82
|
+
* @param {Array} [opt.serverCorsOrigins=['*']] 輸入允許跨域網域陣列,若給予['*']代表允許全部,預設['*']
|
|
83
|
+
* @returns {Object} 回傳事件物件,提供函數getProxies,可監聽事件getRawProxies、add、delete、change
|
|
84
|
+
* @example
|
|
85
|
+
*
|
|
86
|
+
* import _ from 'lodash-es'
|
|
87
|
+
* import wip from './src/WIpProxy.mjs'
|
|
88
|
+
*
|
|
89
|
+
* let wo = wip({
|
|
90
|
+
* // tar: `https://www.google.com`,
|
|
91
|
+
* withServer: true,
|
|
92
|
+
* serverPort: 9000,
|
|
93
|
+
* serverCorsOrigins: ['*'],
|
|
94
|
+
* })
|
|
95
|
+
* wo.on('getRawProxies', (prxsRaw) => {
|
|
96
|
+
* console.log(`已抓取公開代理共 ${_.size(prxsRaw)} 個...`)
|
|
97
|
+
* })
|
|
98
|
+
* wo.on('add', (p, proxies) => {
|
|
99
|
+
* // console.log('新加入代理', { host: p.host, port: p.port }, _.map(proxies, 'proxy'))
|
|
100
|
+
* })
|
|
101
|
+
* wo.on('delete', (p, proxies) => {
|
|
102
|
+
* // console.log('刪除代理', { host: p.host, port: p.port }, _.map(proxies, 'proxy'))
|
|
103
|
+
* })
|
|
104
|
+
* wo.on('change', (proxies) => {
|
|
105
|
+
* // console.log(`有效代理`, _.map(proxies, 'proxy'))
|
|
106
|
+
* console.log(`已檢測有效代理共 ${_.size(proxies)} 個...`)
|
|
107
|
+
* })
|
|
108
|
+
*
|
|
109
|
+
* //browser view: http://localhost:9000/getProxies
|
|
110
|
+
*
|
|
111
|
+
*/
|
|
112
|
+
function WIpProxy(opt = {}) {
|
|
113
|
+
|
|
114
|
+
//src
|
|
115
|
+
let src = get(opt, 'src', '')
|
|
116
|
+
if (!isestr(src)) {
|
|
117
|
+
src = 'https://api.proxyscrape.com/v2/?request=displayproxies' +
|
|
118
|
+
`&protocol=http` +
|
|
119
|
+
// `&protocol=https` +
|
|
120
|
+
`&timeout=5000` +
|
|
121
|
+
// `&country=${join(['tw', 'cn', 'hk', 'jp', 'kr', 'sg', 'my', 'in', 'id', 'th', 'vn'])}` +
|
|
122
|
+
// `&ssl=yes` +
|
|
123
|
+
`&anonymity=elite` //elite匿名代理, all會使用X-Forwarded-For儲存原本ip導致被識別
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//tar
|
|
127
|
+
let tar = get(opt, 'tar', '')
|
|
128
|
+
if (!isestr(tar)) {
|
|
129
|
+
tar = 'https://httpbin.org/ip' //'https://www.google.com'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//timeGetProxies
|
|
133
|
+
let timeGetProxies = get(opt, 'timeGetProxies')
|
|
134
|
+
if (!ispint(timeGetProxies)) {
|
|
135
|
+
timeGetProxies = 30 * 1000 //30s
|
|
136
|
+
}
|
|
137
|
+
timeGetProxies = cint(timeGetProxies)
|
|
138
|
+
|
|
139
|
+
//timeTestProxies
|
|
140
|
+
let timeTestProxies = get(opt, 'timeTestProxies')
|
|
141
|
+
if (!ispint(timeTestProxies)) {
|
|
142
|
+
timeTestProxies = 60 * 1000 //1min
|
|
143
|
+
}
|
|
144
|
+
timeTestProxies = cint(timeTestProxies)
|
|
145
|
+
|
|
146
|
+
//anonymityCheck
|
|
147
|
+
let anonymityCheck = get(opt, 'anonymityCheck')
|
|
148
|
+
if (!isbol(anonymityCheck)) {
|
|
149
|
+
anonymityCheck = true
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//anonymityCheckRepeats
|
|
153
|
+
let anonymityCheckRepeats = get(opt, 'anonymityCheckRepeats')
|
|
154
|
+
if (!ispint(anonymityCheckRepeats)) {
|
|
155
|
+
anonymityCheckRepeats = 2
|
|
156
|
+
}
|
|
157
|
+
anonymityCheckRepeats = cint(anonymityCheckRepeats)
|
|
158
|
+
|
|
159
|
+
//withServer
|
|
160
|
+
let withServer = get(opt, 'withServer')
|
|
161
|
+
if (!isbol(withServer)) {
|
|
162
|
+
withServer = false
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//serverPort
|
|
166
|
+
let serverPort = get(opt, 'serverPort')
|
|
167
|
+
if (!ispint(serverPort)) {
|
|
168
|
+
serverPort = 8080
|
|
169
|
+
}
|
|
170
|
+
serverPort = cint(serverPort)
|
|
171
|
+
|
|
172
|
+
//serverApiName
|
|
173
|
+
let serverApiName = get(opt, 'serverApiName')
|
|
174
|
+
if (!isestr(serverApiName)) {
|
|
175
|
+
serverApiName = 'getProxies'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
//serverCorsOrigins
|
|
179
|
+
let serverCorsOrigins = get(opt, 'serverCorsOrigins', [])
|
|
180
|
+
if (!isearr(serverCorsOrigins)) {
|
|
181
|
+
serverCorsOrigins = ['*']
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//prxsRaw, kpPrx
|
|
185
|
+
let prxsRaw = []
|
|
186
|
+
let kpPrx = {}
|
|
187
|
+
|
|
188
|
+
//myRealIp: 本機真實公網IP, 用於匿名性檢測時比對代理egress是否洩漏
|
|
189
|
+
let myRealIp = ''
|
|
190
|
+
let myRealIpReady = false
|
|
191
|
+
let myRealIpPm = null
|
|
192
|
+
async function _fetchMyRealIp() {
|
|
193
|
+
if (myRealIpReady) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
if (!myRealIpPm) {
|
|
197
|
+
myRealIpPm = (async () => {
|
|
198
|
+
try {
|
|
199
|
+
let res = await axios.get('https://httpbin.org/ip', { timeout: 10000 })
|
|
200
|
+
let origin = get(res, 'data.origin', '')
|
|
201
|
+
if (isestr(origin)) {
|
|
202
|
+
//origin可能為"1.2.3.4"或"1.2.3.4:port", 取首個逗號前且去port
|
|
203
|
+
myRealIp = origin.split(',')[0].trim().split(':')[0]
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
//取不到就算了, 匿名性檢查會自動跳過
|
|
208
|
+
}
|
|
209
|
+
myRealIpReady = true
|
|
210
|
+
})()
|
|
211
|
+
}
|
|
212
|
+
await myRealIpPm
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function _anonymityCheckCore(host, port) {
|
|
216
|
+
if (!anonymityCheck) {
|
|
217
|
+
return { ok: true }
|
|
218
|
+
}
|
|
219
|
+
if (!isestr(myRealIp)) {
|
|
220
|
+
return { ok: true } //沒抓到自己IP就無從比對, 放行
|
|
221
|
+
}
|
|
222
|
+
let agent = new https.Agent({ rejectUnauthorized: false })
|
|
223
|
+
for (let i = 0; i < anonymityCheckRepeats; i++) {
|
|
224
|
+
try {
|
|
225
|
+
let res = await axios.get('https://httpbin.org/ip', {
|
|
226
|
+
proxy: { host, port, protocol: 'http' },
|
|
227
|
+
httpsAgent: agent,
|
|
228
|
+
timeout: 5000,
|
|
229
|
+
headers: {
|
|
230
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/122.0.0.0 Safari/537.36',
|
|
231
|
+
'Accept': 'application/json',
|
|
232
|
+
},
|
|
233
|
+
validateStatus: () => true,
|
|
234
|
+
})
|
|
235
|
+
if (res.status !== 200) {
|
|
236
|
+
return { ok: false, reason: `anonymity status[${res.status}]` }
|
|
237
|
+
}
|
|
238
|
+
let origin = get(res, 'data.origin', '')
|
|
239
|
+
if (!isestr(origin)) {
|
|
240
|
+
return { ok: false, reason: 'anonymity non-json' }
|
|
241
|
+
}
|
|
242
|
+
if (origin.indexOf(myRealIp) >= 0) {
|
|
243
|
+
return { ok: false, reason: `leaks real IP` }
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (err) {
|
|
247
|
+
return { ok: false, reason: trim(err.message || '') }
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return { ok: true }
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async function _getProxiesCore(src) {
|
|
254
|
+
let ps = []
|
|
255
|
+
|
|
256
|
+
try {
|
|
257
|
+
|
|
258
|
+
//res
|
|
259
|
+
let res = await axios.get(src)
|
|
260
|
+
|
|
261
|
+
//c
|
|
262
|
+
let c = res.data
|
|
263
|
+
// console.log('c', c)
|
|
264
|
+
|
|
265
|
+
//sep
|
|
266
|
+
let ss = sep(c, '\n')
|
|
267
|
+
// console.log('ss', ss)
|
|
268
|
+
|
|
269
|
+
//ps
|
|
270
|
+
ps = map(ss, (v) => {
|
|
271
|
+
let [host, port] = v.split(':')
|
|
272
|
+
port = cint(port)
|
|
273
|
+
return {
|
|
274
|
+
proxy: v,
|
|
275
|
+
host,
|
|
276
|
+
port,
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
// console.log('ps', ps)
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
console.log('_getProxiesCore catch', err.message)
|
|
284
|
+
}
|
|
285
|
+
// console.log('ps', ps)
|
|
286
|
+
|
|
287
|
+
return ps
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let b_getProxies = false
|
|
291
|
+
async function _getProxies() {
|
|
292
|
+
// console.log('call getProxies...')
|
|
293
|
+
|
|
294
|
+
let core = async() => {
|
|
295
|
+
|
|
296
|
+
//get
|
|
297
|
+
prxsRaw = await _getProxiesCore(src)
|
|
298
|
+
|
|
299
|
+
//emit
|
|
300
|
+
ev.emit('getRawProxies', prxsRaw)
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
//core
|
|
305
|
+
if (b_getProxies) {
|
|
306
|
+
return
|
|
307
|
+
}
|
|
308
|
+
b_getProxies = true
|
|
309
|
+
await core()
|
|
310
|
+
.catch(() => {}) //吃掉錯誤
|
|
311
|
+
.finally(() => {
|
|
312
|
+
b_getProxies = false
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function _testProxyCore(host, port, url) {
|
|
318
|
+
|
|
319
|
+
//ret
|
|
320
|
+
let ret = (state, msg) => {
|
|
321
|
+
return {
|
|
322
|
+
state,
|
|
323
|
+
msg,
|
|
324
|
+
p: {
|
|
325
|
+
proxy: `${host}:${port}`,
|
|
326
|
+
host,
|
|
327
|
+
port,
|
|
328
|
+
},
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//匿名性預檢: 先確認代理不會透過X-Forwarded-For等洩漏本機真實IP
|
|
333
|
+
let ac = await _anonymityCheckCore(host, port)
|
|
334
|
+
if (!ac.ok) {
|
|
335
|
+
return ret('error', ac.reason)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
//r
|
|
339
|
+
let r = {}
|
|
340
|
+
try {
|
|
341
|
+
|
|
342
|
+
//agent
|
|
343
|
+
let agent = new https.Agent({ rejectUnauthorized: false }) //避免證書錯誤中止
|
|
344
|
+
|
|
345
|
+
//get
|
|
346
|
+
let res = await axios.get(url, {
|
|
347
|
+
proxy: {
|
|
348
|
+
host,
|
|
349
|
+
port,
|
|
350
|
+
protocol: 'http',
|
|
351
|
+
},
|
|
352
|
+
httpsAgent: agent,
|
|
353
|
+
timeout: 5000,
|
|
354
|
+
headers: {
|
|
355
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/122.0.0.0 Safari/537.36',
|
|
356
|
+
'Accept': 'application/json',
|
|
357
|
+
},
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
if (res.status === 200) {
|
|
361
|
+
r = ret('success', res.data)
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
r = ret('error', `status[${res.status}] error`)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
r = ret('error', trim(err.message))
|
|
370
|
+
// if (r.msg.indexOf(`ssl3_get_record`) >= 0) {
|
|
371
|
+
// r.msg = `ssl3_get_record error`
|
|
372
|
+
// }
|
|
373
|
+
}
|
|
374
|
+
// console.log(r)
|
|
375
|
+
|
|
376
|
+
return r
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function _testProxiesCore(prxs) {
|
|
380
|
+
|
|
381
|
+
//pms
|
|
382
|
+
let pms = map(prxs, (p) => {
|
|
383
|
+
let pm = _testProxyCore(p.host, p.port, tar)
|
|
384
|
+
return pm
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
//rrs, allSettled
|
|
388
|
+
let rrs = await Promise.allSettled(pms)
|
|
389
|
+
// console.log('rrs', rrs)
|
|
390
|
+
|
|
391
|
+
//psValid, psInvalid
|
|
392
|
+
let psValid = []
|
|
393
|
+
let psInvalid = []
|
|
394
|
+
each(rrs, (v) => {
|
|
395
|
+
|
|
396
|
+
//be
|
|
397
|
+
let p = get(v, 'value.p', null)
|
|
398
|
+
let be = iseobj(p) && isestr(get(p, 'proxy'))
|
|
399
|
+
|
|
400
|
+
//check
|
|
401
|
+
if (!be) {
|
|
402
|
+
return true //跳出換下一個
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
//b
|
|
406
|
+
let status = get(v, 'status', '')
|
|
407
|
+
let b1 = status === 'fulfilled'
|
|
408
|
+
let state = get(v, 'value.state', '')
|
|
409
|
+
let b2 = state === 'success'
|
|
410
|
+
let b = b1 && b2
|
|
411
|
+
|
|
412
|
+
//push
|
|
413
|
+
if (b) {
|
|
414
|
+
psValid.push(p)
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
psInvalid.push(p)
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
psValid,
|
|
424
|
+
psInvalid,
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
let b_testProxies = false
|
|
429
|
+
async function _testProxies() {
|
|
430
|
+
// console.log('call testProxies...')
|
|
431
|
+
|
|
432
|
+
let core = async() => {
|
|
433
|
+
|
|
434
|
+
//確保本機真實IP已取得, 供匿名性檢查比對
|
|
435
|
+
await _fetchMyRealIp()
|
|
436
|
+
|
|
437
|
+
//get
|
|
438
|
+
let r = await _testProxiesCore(prxsRaw)
|
|
439
|
+
|
|
440
|
+
//emit add
|
|
441
|
+
each(r.psValid, (p) => {
|
|
442
|
+
kpPrx[p.proxy] = p
|
|
443
|
+
ev.emit('add', p, values(kpPrx))
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
//emit delete
|
|
447
|
+
each(r.psInvalid, (p) => {
|
|
448
|
+
delete kpPrx[p.proxy]
|
|
449
|
+
ev.emit('delete', p, values(kpPrx))
|
|
450
|
+
})
|
|
451
|
+
|
|
452
|
+
//emit change
|
|
453
|
+
ev.emit('change', values(kpPrx))
|
|
454
|
+
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
//core
|
|
458
|
+
if (b_testProxies) {
|
|
459
|
+
return
|
|
460
|
+
}
|
|
461
|
+
b_testProxies = true
|
|
462
|
+
await core()
|
|
463
|
+
.catch(() => {}) //吃掉錯誤
|
|
464
|
+
.finally(() => {
|
|
465
|
+
b_testProxies = false
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function init() {
|
|
471
|
+
|
|
472
|
+
//取得代理清單
|
|
473
|
+
if (true) {
|
|
474
|
+
_getProxies()
|
|
475
|
+
setInterval(() => {
|
|
476
|
+
_getProxies()
|
|
477
|
+
}, timeGetProxies)
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
//過濾出有效代理清單, 延遲3s觸發, 給時間抓取
|
|
481
|
+
if (true) {
|
|
482
|
+
setTimeout(() => {
|
|
483
|
+
_testProxies()
|
|
484
|
+
setInterval(() => {
|
|
485
|
+
_testProxies()
|
|
486
|
+
}, timeTestProxies)
|
|
487
|
+
}, 3000)
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
async function getProxies() {
|
|
493
|
+
let vs
|
|
494
|
+
await waitFun(() => {
|
|
495
|
+
vs = values(kpPrx)
|
|
496
|
+
return size(vs) > 0
|
|
497
|
+
})
|
|
498
|
+
return vs
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
//ev
|
|
502
|
+
let ev = evem()
|
|
503
|
+
|
|
504
|
+
//withServer
|
|
505
|
+
if (withServer) {
|
|
506
|
+
provideServer(getProxies, {
|
|
507
|
+
port: serverPort,
|
|
508
|
+
apiName: serverApiName,
|
|
509
|
+
corsOrigins: serverCorsOrigins,
|
|
510
|
+
})
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
async function getProxiesOnce() {
|
|
514
|
+
await _getProxies()
|
|
515
|
+
await _testProxies()
|
|
516
|
+
let ps = await getProxies()
|
|
517
|
+
return ps
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
//save
|
|
521
|
+
ev.init = init
|
|
522
|
+
ev.getProxies = getProxies
|
|
523
|
+
ev.getProxiesOnce = getProxiesOnce
|
|
524
|
+
|
|
525
|
+
return ev
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
export default WIpProxy
|
|
530
|
+
</code></pre>
|
|
531
|
+
</article>
|
|
532
|
+
</section>
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
</div>
|
|
540
|
+
|
|
541
|
+
<br class="clear">
|
|
542
|
+
|
|
543
|
+
<footer>
|
|
544
|
+
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Fri Apr 17 2026 13:21:29 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
|
|
545
|
+
</footer>
|
|
546
|
+
|
|
547
|
+
<script>prettyPrint();</script>
|
|
548
|
+
<script src="scripts/polyfill.js"></script>
|
|
549
|
+
<script src="scripts/linenumber.js"></script>
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
</body>
|
|
554
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|