Advertisement
Guest User

Untitled

a guest
Mar 15th, 2025
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. from telethon import TelegramClient
  2. from telethon.errors import SessionPasswordNeededError
  3. from telethon.tl.functions.account import GetAuthorizationsRequest, ResetAuthorizationRequest
  4.  
  5. # Настройки Telegram
  6. api_id = ''  # Сюда ваш API ID
  7. api_hash = ''  # Сюда ваш API Hash
  8. phone_number = '+Xxxxxxxxxxx'  # Ваш номер телефона
  9. model_device = '' # Сюда модель трубы/девайса, которое надо завершать, пример - iPhone 16
  10.  
  11. client = TelegramClient('session_name', api_id, api_hash)
  12.  
  13. async def terminate_phone_session():
  14.     await client.start(phone=phone_number)
  15.  
  16.     try:
  17.         authorizations = await client(GetAuthorizationsRequest())
  18.         for auth in authorizations.authorizations:
  19.             date_created = auth.date_created.strftime('%Y-%m-%d %H:%M:%S')
  20.             print(f"Устройство: {auth.device_model}, IP: {auth.ip}, Дата создания: {date_created}")
  21.  
  22.             if auth.device_model == model_device:
  23.                 print(f"Завершаем сессию: {auth.device_model} ({auth.ip})")
  24.                 await client(ResetAuthorizationRequest(hash=auth.hash))
  25.                 print("Сессия завершена.")
  26.                 break
  27.     except SessionPasswordNeededError:
  28.         print("Требуется двухэтапная аутентификация. Введите пароль.")
  29.     except Exception as e:
  30.         print(f"Ошибка: {e}")
  31.  
  32. with client:
  33.     client.loop.run_until_complete(terminate_phone_session())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement