-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathautowhite.py
110 lines (99 loc) · 5.91 KB
/
autowhite.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
106
107
108
109
110
import gol
import logs
import os
from netaddr.ip import IPAddress
def if_ip4or6(cfgstr):
ipFlg = False
if '/' in cfgstr:
text = cfgstr[:cfgstr.rfind('/')]
else:
text = cfgstr
try:
addr = IPAddress(text)
ipFlg = True
except:
ipFlg = False
if ipFlg == True:
return addr.version
else:
return False
def anti_abuse():
os.system('iptables -A OUTPUT -m string --string "fast.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speedtest.net" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speedtest.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speedtest.cn" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "test.ustc.edu.cn" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "10000.gd.cn" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "db.laomoe.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "jiyou.cloud" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "ovo.speedtestcustom.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speed.cloudflare.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speedtest" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speedtest" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string ".speed" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "speed." --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string ".speed." --algo bm -j DROP')
def anti_bt():
os.system('iptables -A OUTPUT -m string --string "torrent" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string ".torrent" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "peer_id=" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "announce" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "info_hash" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "get_peers" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "find_node" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "BitTorrent" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "announce_peer" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "BitTorrent protocol" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "announce.php?passkey=" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "magnet:" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "xunlei" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "sandai" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "Thunder" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "XLLiveUD" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "ethermine.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "antpool.one" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "antpool.com" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "pool.bar" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "get_peers" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "announce_peer" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "find_node" --algo bm -j DROP')
os.system('iptables -A OUTPUT -m string --string "seed_hash" --algo bm -j DROP')
def init():
os.system("sudo rm -rf ./adoptip.csv")
os.system("sudo rm -rf ./failedip.csv")
os.system("iptables -F")
os.system("ip6tables -F")
os.system("iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP")
os.system("iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP")
os.system("iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP")
os.system("iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP")
for sub_port in gol.get_value('port'):
os.system("iptables -I INPUT -p TCP --dport " + str(sub_port) + " -j DROP")
os.system("iptables -I INPUT -p UDP --dport " + str(sub_port) + " -j DROP")
os.system("ip6tables -I INPUT -p TCP --dport " + str(sub_port) + " -j DROP")
os.system("ip6tables -I INPUT -p UDP --dport " + str(sub_port) + " -j DROP")
os.system("iptables -A INPUT -p TCP --dport " + str(sub_port) + " -m connlimit --connlimit-above 1000 -j REJECT")
os.system("iptables -A INPUT -p UDP --dport " + str(sub_port) + " -m connlimit --connlimit-above 1000 -j REJECT")
os.system("ip6tables -A INPUT -p TCP --dport " + str(sub_port) + " -m connlimit --connlimit-above 1000 -j REJECT")
os.system("ip6tables -A INPUT -p UDP --dport " + str(sub_port) + " -m connlimit --connlimit-above 1000 -j REJECT")
def add(ip):
if os.path.isfile("./adoptip.csv"):
r = open("./adoptip.csv", mode='r')
iplist = r.read()
r.close()
else:
iplist = ""
if ip in iplist:
print(ip+"已经添加过白名单")
return "已经添加过白名单"
else:
for sub_port in gol.get_value('port'):
if if_ip4or6(ip) == 4:
os.system("iptables -I INPUT -s "+ip +" -p TCP --dport " + str(sub_port) + " -j ACCEPT")
os.system("iptables -I INPUT -s "+ip +" -p UDP --dport " + str(sub_port) + " -j ACCEPT")
else:
os.system("ip6tables -I INPUT -s "+ip +" -p TCP --dport " + str(sub_port) + " -j ACCEPT")
os.system("ip6tables -I INPUT -s "+ip +" -p UDP --dport " + str(sub_port) + " -j ACCEPT")
print(ip+"已添加到白名单")
logs.adoptadd(ip)
return "已添加到白名单"