-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
40 lines (32 loc) · 869 Bytes
/
Copy pathcode.js
File metadata and controls
40 lines (32 loc) · 869 Bytes
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
// Author: iBug
function belongsToSubnet(host, list) {
var ip = host.split(".");
ip = 0x1000000 * Number(ip[0]) + 0x10000 * Number(ip[1]) +
0x100 * Number(ip[2]) + Number(ip[3]);
if (ip < list[0][0])
return false;
// Binary search
var x = 0, y = list.length, middle;
while (y - x > 1) {
middle = Math.floor((x + y) / 2);
if (list[middle][0] < ip)
x = middle;
else
y = middle;
}
// Match
var masked = ip & list[x][1];
return (masked ^ list[x][0]) == 0;
}
var proxy = "__PROXY__";
var direct = "DIRECT";
function FindProxyForURL(url, host) {
var remote = dnsResolve(host);
if (belongsToSubnet(remote, WHITELIST)) {
return direct;
}
return proxy;
}
// Format: [Hex IP, mask]
// e.g. 1.0.1.0/24 = [0x80008000, 0xFFFFFF00]
// Source: http://www.ipdeny.com/ipblocks/data/aggregated/cn-aggregated.zone