-
Notifications
You must be signed in to change notification settings - Fork 0
/
genacl_proxy_gfw_bypass_china_ip.py
105 lines (80 loc) · 2.76 KB
/
genacl_proxy_gfw_bypass_china_ip.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
from urllib import request, parse
import logging
import sys
import json
from datetime import datetime
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
GFW_TRANSLATED_URL = "https://raw.githubusercontent.com/NateScarlet/gfwlist.acl/master/gfwlist.acl.json"
PRIVATE_IP_LIST_URL = "https://raw.githubusercontent.com/carrnot/china-ip-list/main/private.txt"
CHINA_IP_LIST_URL = "https://raw.githubusercontent.com/carrnot/china-ip-list/release/ip.txt"
CHINA_DOMAIN_LIST_URL = "https://raw.githubusercontent.com/carrnot/china-domain-list/release/domain.txt"
CUSTOM_BYPASS = [
"||configuration.ls.apple.com",
"||friend.gc.apple.com",
"||p126-caldav.icloud.com",
"||p126-contacts.icloud.com",
# "||files.1drv.com",
# "||self.events.data.microsoft.com",
"||setup.icloud.com",
"||weather-edge.apple.com"
]
CUSTOM_PROXY = [
]
def fetch_url_content(url):
logger.info("FETCHING {}".format(url))
r = request.urlopen(url)
return r.read()
def write_gfw_list(fp):
gfw_json = fetch_url_content(GFW_TRANSLATED_URL)
gfw_obj = json.loads(gfw_json)
for line in gfw_obj["blacklist"]:
fp.write(line.encode("utf-8"))
fp.write(b"\n")
def write_private_ip(fp):
private_ip_list = fetch_url_content(PRIVATE_IP_LIST_URL)
fp.write(private_ip_list)
fp.write(b"\n")
def write_china_ip(fp):
china_ip_list = fetch_url_content(CHINA_IP_LIST_URL)
fp.write(china_ip_list)
fp.write(b"\n")
def write_china_domain(fp):
china_domain_list = fetch_url_content(CHINA_DOMAIN_LIST_URL)
body = china_domain_list.decode("utf-8")
for line in body.split("\n"):
if line == "":
continue
fp.write(("||"+line).encode("utf-8"))
fp.write(b"\n")
fp.write(b"\n")
try:
output_file_path = sys.argv[1]
except:
output_file_path = "./shadowsocks.acl"
logger.info("WRITING {}".format(output_file_path))
with open(output_file_path, 'wb') as fp:
now = datetime.now()
fp.write(b"# Generated by genacl.py\n")
fp.write("# Time: {}\n".format(now.isoformat()).encode("utf-8"))
fp.write(b"\n")
fp.write(b"[proxy_all]\n")
# fp.write(b"\n[proxy_list]\n")
# write_gfw_list(fp)
# if len(CUSTOM_PROXY) > 0:
# logger.info("CUSTOM_PROXY {} lines".format(len(CUSTOM_PROXY)))
# for a in CUSTOM_PROXY:
# fp.write(a.encode("utf-8"))
# fp.write(b"\n")
fp.write(b"\n[bypass_list]\n")
write_private_ip(fp)
write_china_domain(fp)
if len(CUSTOM_BYPASS) > 0:
logger.info("CUSTOM_BYPASS {} lines".format(len(CUSTOM_BYPASS)))
for a in CUSTOM_BYPASS:
fp.write(a.encode("utf-8"))
fp.write(b"\n")
fp.write(b"\n")
# write_china_ip(fp)
logger.info("DONE")