-
Notifications
You must be signed in to change notification settings - Fork 1
/
infusor.py
executable file
·196 lines (164 loc) · 6.1 KB
/
infusor.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import mysql.connector
import sys,os
from Naked.toolshed.shell import execute_rb
import socket
import os
mydb = mysql.connector.connect(
host="162.241.2.202",
database="andredev_trabalho_redes2",
user="andredev_redes2",
passwd="redes2"
)
mycursor = mydb.cursor()
def exibirValidarIpPaises():
mycursor.execute("SELECT * FROM validarippaises")
for tb in mycursor:
print(tb)
def validarIpPaises():
arq = open('./flags/paises.flag', 'w')
mycursor.execute("SELECT * FROM validarippaises")
for row in mycursor:
print(row[2], file=arq)
arq.close()
os.system('./aplicar.sh')
def zerarFlagsValidarIpPaises():
mycursor.execute("UPDATE validarippaises SET FLAG=0")
def selecionarFlagsValidarIpPaises():
mycursor.execute("UPDATE validarippaises SET FLAG=1")
def exibirPaisesBloqueados():
mycursor.execute("SELECT PAIS FROM validarippaises WHERE FLAG=1")
for tb in mycursor:
print(tb)
def exibirPaisesLivres():
mycursor.execute("SELECT PAIS FROM validarippaises WHERE FLAG=0")
for tb in mycursor:
print(tb)
def bloquearPaisEspecifico():
while 1:
mycursor.execute('SELECT * FROM validarippaises WHERE FLAG="0"')
for tb in mycursor:
print(tb)
escolha = input("Digite o codigo do pais(0=Voltar): ")
if escolha == "0":
return
else:
mycursor.execute('UPDATE validarippaises SET FLAG=1 WHERE ID="'+escolha+'"')
os.system("cls")
def liberarPaisEspecifico():
while 1:
mycursor.execute('SELECT * FROM validarippaises WHERE FLAG="1"')
for tb in mycursor:
print(tb)
escolha = input("Digite o codigo do pais(0=Voltar): ")
if escolha == "0":
return
else:
mycursor.execute('UPDATE validarippaises SET FLAG=0 WHERE ID="'+escolha+'"')
os.system("cls")
def adicionarLinkEspecifico():
link = input("Digite o link/IP a ser bloqueado: ")
mycursor.execute('INSERT INTO linksespecificos(ALVO) VALUES ("'+link+'")')
validarLinks()
def validarLinks():
arq = open('./manual/manual.misto', 'w')
mycursor.execute('SELECT * FROM linksespecificos')
for row in mycursor:
print(row[1], file=arq)
arq.close()
def exibirLinksBloqueados():
mycursor.execute('SELECT * FROM linksespecificos')
for tb in mycursor:
print(tb)
def removerLinkEspecifico():
exibirLinksBloqueados()
cod = input("Digite o codigo a ser liberado: ")
mycursor.execute('DELETE FROM linksespecificos WHERE ID="'+cod+'"')
mycursor.execute('ALTER TABLE linksespecificos AUTO_INCREMENT = 1')
validarLinks()
def menu():
validarIpPaises()
while 1:
menu = True
while menu:
print("""
--------------------------
IP local: """ + socket.gethostbyname(socket.gethostname())+"""
--------------------------
MENU PRINCIPAL
1.Adicionar na Blacklist
2.Adicionar na WhiteList
3.Exibir
4.Validar tudo
5.Sair
--------------------------
""")
menu = input("Escolha uma opcao: ")
if menu == "1":
print("""
--------------------------
MENU - BLACKLIST
1.Pais especifico
2.Ip especifico
3.Todos paises
--------------------------
""")
menuBlacklist = input("Escolha uma opcao: ")
if menuBlacklist == "1":
bloquearPaisEspecifico()
validarIpPaises()
elif menuBlacklist == "2":
adicionarLinkEspecifico()
elif menuBlacklist == "3":
selecionarFlagsValidarIpPaises()
validarIpPaises()
elif menuBlacklist != "":
print("\n Opcao Invalida. Tente Novamente")
elif menu == "2":
print("""
--------------------------
MENU - BLACKLIST
1.Pais especifico
2.Ip especifico
3.Todos paises
--------------------------
""")
menuWhitelist = input("Escolha uma opcao: ")
if menuWhitelist == "1":
liberarPaisEspecifico()
validarIpPaises()
elif menuWhitelist == "2":
removerLinkEspecifico()
elif menuWhitelist == "3":
zerarFlagsValidarIpPaises()
validarIpPaises()
elif menuWhitelist != "":
print("\n Opcao Invalida. Tente Novamente")
elif menu == "3":
print("""
--------------------------
MENU - EXIBICAO
1.Exibir todos paises
2.Exibir paises bloqueados
3.Exibir paises nao-bloqueados
4.Exibir links/IPs
--------------------------
""")
menuExibicao = input("Escolha uma opcao: ")
if menuExibicao == "1":
exibirValidarIpPaises()
elif menuExibicao == "2":
exibirPaisesBloqueados()
elif menuExibicao == "3":
exibirPaisesLivres()
elif menuExibicao == "4":
exibirLinksBloqueados()
elif menuExibicao != "":
print("\n Opcao Invalida. Tente Novamente")
elif menu == "4":
validarIpPaises()
validarLinks()
elif menu == "5":
exit()
elif menu != "":
print("\n Opcao Invalida. Tente Novamente")
menu()