From 1b1dfcc29b861f8352a56aa30c162ef64ee11946 Mon Sep 17 00:00:00 2001 From: walter Date: Sat, 7 Jun 2025 16:23:11 +0000 Subject: [PATCH] send_ips_report.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Envia os IP´s das interfaces para um email. --- send_ips_report.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 send_ips_report.py diff --git a/send_ips_report.py b/send_ips_report.py new file mode 100644 index 0000000..00793fd --- /dev/null +++ b/send_ips_report.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +import smtplib +from email.mime.text import MIMEText +from datetime import datetime +import subprocess + +# Configurações +smtp_server = "smtp.gmail.com" +smtp_port = 587 +email_from = "walter@h4t.eti.br" +email_to = "walter@h4t.eti.br" +app_password = "pzqw mwgc qctj imqs" +subject = f"Relatório de IPs - {datetime.now().strftime('%Y-%m-%d %H:%M')}" + +# Interfaces com nome amigável +interfaces = { + "eth8": "Algar1", + "eth6": "Algar2", + "eth7": "Claro" +} + +body = f"Relatório de IPs Públicos - {datetime.now()}\n" +body += "----------------------------------------\n" +for iface, name in interfaces.items(): + try: + ip = subprocess.check_output(["curl", "-s", "--interface", iface, "https://ifconfig.me"], timeout=10).decode().strip() + except: + ip = "IP inválido ou não detectado" + body += f"{name} ({iface}) => IP: {ip}\n" +body += "----------------------------------------" + +# Construir email +msg = MIMEText(body) +msg["Subject"] = subject +msg["From"] = email_from +msg["To"] = email_to + +# Enviar email +try: + with smtplib.SMTP(smtp_server, smtp_port) as server: + server.starttls() + server.login(email_from, app_password) + server.send_message(msg) + print("Email enviado com sucesso.") +except Exception as e: + print(f"Falha ao enviar email: {e}")