forked from breakwa11/gfw_whitelist
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ss_lanip.pac
75 lines (69 loc) · 1.73 KB
/
ss_lanip.pac
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
var direct = "DIRECT;";
var wall_proxy = function(){ return "__PROXY__"; };
var wall_v6_proxy = function(){ return "__PROXY__"; };
var nowall_proxy = function(){ return direct; };
var ip_proxy = function(){ return wall_proxy(); };
var ipv6_proxy = function(){ return wall_v6_proxy(); };
/*
* Copyright (C) 2014 breakwa11
* https://github.com/breakwa11/gfw_whitelist
*/
var subnetIpRangeList = [
0,1,
167772160,184549376, //10.0.0.0/8
2886729728,2887778304, //172.16.0.0/12
3232235520,3232301056, //192.168.0.0/16
2130706432,2130706688 //127.0.0.0/24
];
var hasOwnProperty = Object.hasOwnProperty;
function check_ipv4(host) {
var re_ipv4 = /^\d+\.\d+\.\d+\.\d+$/g;
if (re_ipv4.test(host)) {
return true;
}
}
function check_ipv6(host) {
var re_ipv6 = /^\[?([a-fA-F0-9]{0,4}\:){1,7}[a-fA-F0-9]{0,4}\]?$/g;
if (re_ipv6.test(host)) {
return true;
}
}
function check_ipv6_dns(dnsstr) {
var re_ipv6 = /([a-fA-F0-9]{0,4}\:){1,7}[a-fA-F0-9]{0,4}(%[0-9]+)?/g;
if (re_ipv6.test(dnsstr)) {
return true;
}
}
function convertAddress(ipchars) {
var bytes = ipchars.split('.');
var result = (bytes[0] << 24) |
(bytes[1] << 16) |
(bytes[2] << 8) |
(bytes[3]);
return result >>> 0;
}
function isInSubnetRange(ipRange, intIp) {
for ( var i = 0; i < 10; i += 2 ) {
if ( ipRange[i] <= intIp && intIp < ipRange[i+1] )
return true;
}
}
function getProxyFromIP(strIp) {
var intIp = convertAddress(strIp);
if ( isInSubnetRange(subnetIpRangeList, intIp) ) {
return direct;
}
return ip_proxy();
}
function FindProxyForURL(url, host) {
if ( isPlainHostName(host) === true ) {
return direct;
}
if ( check_ipv4(host) === true ) {
return getProxyFromIP(host);
}
if ( check_ipv6(host) === true ) {
return ipv6_proxy();
}
return wall_proxy();
}