-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathFindMixedProxies.js
77 lines (62 loc) · 1.91 KB
/
FindMixedProxies.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
import url from 'url';
import { isIP } from './regexes.js';
const getProxyType = string => {
try {
const first = /^(?:(\w+)(?::(\w+))?@)?((?:\d{1,3})(?:\.\d{1,3}){3})(?::(\d{1,5}))?$/.exec(string);
if (first) {
const log = first[1];
const pass = first[2];
return {
type: 'v4',
auth: log && pass ? `${log}:${pass}` : 'none',
host: first[3],
port: Number(first[4])
};
}
const second = url.parse(!string.startsWith('http') ? `http://${string}` : string);
if (second) {
if (!second.port) {
const [port, log, pass] = second.path
.replaceAll('/', '')
.split(':')
.filter(item => item.length > 0);
const nextPort = Number(port);
if (nextPort >= 0 && nextPort <= 65535) {
return {
type: isIP(second.hostname) ? 'v4' : 'url',
auth: `${log}:${pass}`,
host: second.hostname,
port: nextPort
};
}
return null;
}
return {
type: isIP(second.hostname) ? 'v4' : 'url',
auth: second.auth ? second.auth : 'none',
host: second.hostname,
port: Number(second.port)
};
}
return null;
} catch {
return null;
}
};
const findMixedProxies = array => {
const successed = [];
const failed = [];
for (const string of array) {
const result = getProxyType(string);
if (result) {
successed.push(result);
} else {
failed.push(string);
}
}
return {
successed,
failed
};
};
export default findMixedProxies;