IvanCastl

WhatsApp OSINT

Sep 29th, 2025
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.09 KB | Cybersecurity | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.service import Service
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.common.action_chains import ActionChains
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. from selenium.webdriver.support import expected_conditions as EC
  7. import datetime
  8. import time
  9. import requests
  10.  
  11. # ------------------ CONFIGURACIÓN ------------------
  12. chrome_driver_path = r"C:\Downloads\chromedriver-win64\chromedriver.exe"
  13. chrome_binary_path = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
  14. user_data_dir = r"C:\Documents\ChromeProfile"  # carpeta para guardar sesión
  15. user_to_track = "Prueba"  # reemplaza con el contacto que quieres seguir
  16.  
  17. # Telegram
  18. BOT_TOKEN = "8156257450:AAEsjajsajskai5acs8a96ca5c1sctdñclacl"
  19. CHAT_ID = "2085145625"
  20.  
  21. # ------------------ FUNCIONES ------------------
  22. def send_telegram_message(text):
  23.     url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
  24.     data = {"chat_id": CHAT_ID, "text": text}
  25.     try:
  26.         response = requests.post(url, data=data)
  27.         if response.status_code != 200:
  28.             print(f"❌ Error enviando mensaje: {response.text}")
  29.     except Exception as e:
  30.         print(f"❌ Excepción enviando mensaje: {e}")
  31.  
  32. def find_user_chat(user_name):
  33.     """Busca y entra al chat del usuario"""
  34.     try:
  35.         search_box = driver.find_element(By.XPATH, '//*[@id="side"]/div[1]/div/div[2]/div/div/div[1]/p')
  36.         search_box.click()
  37.         actions = ActionChains(driver)
  38.         actions.send_keys(user_name).perform()
  39.         time.sleep(2)  # espera que aparezcan resultados
  40.         user_element = driver.find_element(By.XPATH, '//*[@id="pane-side"]/div[1]/div/div/div[2]/div/div')
  41.         user_element.click()
  42.         print(f"✅ Chat encontrado y abierto: {user_name}")
  43.         return True
  44.     except Exception as e:
  45.         print(f"❌ No se pudo encontrar el usuario: {e}")
  46.         return False
  47.  
  48. def check_online_status():
  49.     """Verifica si el usuario está en línea"""
  50.     try:
  51.         online_span = driver.find_element(By.XPATH, "//span[@title='en línea']")  # Español
  52.         return True
  53.     except:
  54.         return False
  55.  
  56. # ------------------ INICIALIZAR CHROME ------------------
  57. options = webdriver.ChromeOptions()
  58. options.binary_location = chrome_binary_path
  59. options.add_argument(f"user-data-dir={user_data_dir}")  # Guarda sesión
  60. options.add_experimental_option('excludeSwitches', ['enable-logging'])
  61.  
  62. service = Service(executable_path=chrome_driver_path)
  63. driver = webdriver.Chrome(service=service, options=options)
  64. driver.get("https://web.whatsapp.com")
  65.  
  66. # Espera hasta que cargue la barra lateral de chats
  67. WebDriverWait(driver, 60).until(
  68.     EC.presence_of_element_located((By.XPATH, '//*[@id="side"]/div[1]/div/div[2]/div/div/div[1]/p'))
  69. )
  70. print("✅ WhatsApp Web cargado y listo")
  71.  
  72. # ------------------ SEGUIMIENTO ------------------
  73. if find_user_chat(user_to_track):
  74.     print(f"⏱ Comenzando seguimiento de {user_to_track}...")
  75.     previous_state = "OFFLINE"
  76.     first_online_time = None
  77.     while True:
  78.         try:
  79.             is_online = check_online_status()
  80.             now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
  81.             if is_online and previous_state == "OFFLINE":
  82.                 print(f"[{now}] ✅ {user_to_track} está ONLINE")
  83.                 send_telegram_message(f"✅ {user_to_track} está ONLINE ({now})")
  84.                 first_online_time = time.time()
  85.                 previous_state = "ONLINE"
  86.  
  87.             elif not is_online and previous_state == "ONLINE":
  88.                 total_online = time.time() - first_online_time
  89.                 print(f"[{now}] ❌ {user_to_track} se desconectó. Duración: {int(total_online)} segundos")
  90.                 send_telegram_message(f"❌ {user_to_track} se desconectó. Duración: {int(total_online)} segundos ({now})")
  91.                 previous_state = "OFFLINE"
  92.  
  93.             time.sleep(5)  # espera 5 segundos antes de la siguiente comprobación
  94.         except Exception as e:
  95.             print(f"❌ Error durante seguimiento: {e}")
  96.             break
  97.  
Advertisement
Add Comment
Please, Sign In to add comment