Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telethon import TelegramClient
- from telethon.errors import SessionPasswordNeededError
- from telethon.tl.functions.account import GetAuthorizationsRequest, ResetAuthorizationRequest
- # Настройки Telegram
- api_id = '' # Сюда ваш API ID
- api_hash = '' # Сюда ваш API Hash
- phone_number = '+Xxxxxxxxxxx' # Ваш номер телефона
- model_device = '' # Сюда модель трубы/девайса, которое надо завершать, пример - iPhone 16
- client = TelegramClient('session_name', api_id, api_hash)
- async def terminate_phone_session():
- await client.start(phone=phone_number)
- try:
- authorizations = await client(GetAuthorizationsRequest())
- for auth in authorizations.authorizations:
- date_created = auth.date_created.strftime('%Y-%m-%d %H:%M:%S')
- print(f"Устройство: {auth.device_model}, IP: {auth.ip}, Дата создания: {date_created}")
- if auth.device_model == model_device:
- print(f"Завершаем сессию: {auth.device_model} ({auth.ip})")
- await client(ResetAuthorizationRequest(hash=auth.hash))
- print("Сессия завершена.")
- break
- except SessionPasswordNeededError:
- print("Требуется двухэтапная аутентификация. Введите пароль.")
- except Exception as e:
- print(f"Ошибка: {e}")
- with client:
- client.loop.run_until_complete(terminate_phone_session())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement