-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
80 lines (69 loc) · 2.51 KB
/
run.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
import os
import requests
ip_url = 'https://raw.githubusercontent.com/QiuSimons/Chnroute/master/dist/chnroute/chnroute.txt'
ip6_url = 'https://raw.githubusercontent.com/QiuSimons/Chnroute/master/dist/chnroute/chnroute-v6.txt'
list_url = 'https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt'
def getChnroute(ip_url):
try:
response = requests.get(ip_url, timeout=5)
except requests.exceptions.Timeout:
print("IP Time Out!!!")
else:
data = response.text
lines = data.split('\n')
new_lines = []
for line in lines:
if not line.startswith('17.'):
new_line = 'IP-CIDR,' + line + ',Direct,no-resolve'
new_lines.append(new_line)
del new_lines[-1]
new_lines.append('\n')
with open('./head.txt', 'a', encoding='utf-8') as f:
f.write('\n'.join(new_lines))
def getChnroute6(ip6_url):
try:
response = requests.get(ip6_url, timeout=5)
except requests.exceptions.Timeout:
print("IP Time Out!!!")
else:
data = response.text
lines = data.split('\n')
new_lines = []
for line in lines:
new_line = 'IP-CIDR,' + line + ',Direct,no-resolve'
new_lines.append(new_line)
del new_lines[-1]
new_lines.append('\n')
with open('./head.txt', 'a', encoding='utf-8') as f:
f.write('\n'.join(new_lines))
def getChnlist(list_url):
try:
response = requests.get(list_url, timeout=5)
except requests.exceptions.Timeout:
print("List Time Out!!!")
else:
data = response.text
lines = data.split('\n')
new_lines = []
for line in lines:
if not line.startswith('regexp:'):
if line.startswith('full:'):
line = line.strip('full:')
new_line = 'DOMAIN-SUFFIX,' + line + ',Direct'
new_lines.append(new_line)
else:
new_line = 'DOMAIN-SUFFIX,' + line + ',Direct'
new_lines.append(new_line)
del new_lines[-1]
new_lines.append('\n')
with open('./head.txt', 'a', encoding='utf-8') as f:
f.write('\n'.join(new_lines))
def merge():
with open("./head.txt","a") as head, open("./tail.txt","r") as tail:
for line in tail:
head.write(line)
os.rename('./head.txt', './Rocket.conf')
getChnlist(list_url)
getChnroute(ip_url)
#getChnroute6(ip6_url)
merge()