class TelegramLogin: def __init__(self, phone, session_dir): self.phone = phone self.session_dir = session_dir os.mkdir(self.session_dir) self.app = Client("app", api_id, api_hash, workdir=self.session_dir) self.app.connect() def request_code(self): try: sent_code = self.app.send_code(self.phone) print(sent_code) if sent_code.type != "sms": self.bye() return False except exceptions.bad_request_400.PhoneNumberBanned: self.bye() return False self.sent_code = sent_code return True def create_session(self, code) -> User: signed_up = None signed_in = self.app.sign_in(self.phone, self.sent_code.phone_code_hash, code) if isinstance(signed_in, User): self.bye() return False first_name, last_name = gen_person() while not signed_up: try: signed_up = self.app.sign_up(self.phone, self.sent_code.phone_code_hash, first_name=first_name, last_name=last_name) if isinstance(signed_in, TermsOfService): self.app.accept_terms_of_service(signed_in.id) self.app.disconnect() return signed_up except FloodWait as e: print("Sleeping ", e.x) time.sleep(e.x) def bye(self): self.app.disconnect() shutil.rmtree(self.session_dir)
def main(): global username, replacer, client files = os.listdir() sessions = [] for file in files: if file.endswith('.session'): sessions.append(file) i = 0 phones = [] for session in sessions: phones.append(session.split('.session')[0]) client = Client(phones[i], api_id, api_hash) loop.run_until_complete(client.connect()) me = loop.run_until_complete(client.get_me()) try: name = me['first_name'] + ' ' + me['last_name'] except: name = me['first_name'] name = name + '\n (' + me['phone_number'] + ')' print(str(i + 1) + ". " + name) loop.run_until_complete(client.disconnect()) i += 1 print(str(i + 1) + ". New login") c = int(input("Enter valid choice: ")) if c == len(phones) + 1: phone = input("Enter phone: ") client = Client(phone, api_id, api_hash) loop.run_until_complete(client.connect()) code_hash = loop.run_until_complete( client.send_code(phone))['phone_code_hash'] code = input("Enter code: ") loop.run_until_complete(client.sign_in(phone, code_hash, code)) else: client = Client(phones[c - 1], api_id, api_hash) loop.run_until_complete(client.connect()) me = loop.run_until_complete(client.get_me()) try: name = me['first_name'] + ' ' + me['last_name'] except: name = me['first_name'] wel = "\nLogged in as: " + name + ' (' + me['phone_number'] + ')\n' print(wel) path = input('Enter path : ') username = input("Enter phone no. , channel link, group link ,etc. : ") replacer = os.path.dirname(path) + '/' upload(path)
def add_session(self): app = Client('test_one', api_id, api_hash) app.connect() phone_number = input('Phone_num: ') code_hash = app.send_code(phone_number).phone_code_hash code = input('Conf: ') try: app.sign_in(phone_number, code_hash, code) except SessionPasswordNeeded: passs = input('Pass: '******'done') app.disconnect()
class StateManager(Client): state = None one = None def __init__(self, config): print('State_manager started') self.api_id = config.api_id self.api_hash = config.api_hash pass def start_session(self, phone_number): try: self.app = Client('test_second', self.api_id, self.api_hash) self.app.connect() self.phone = phone_number self.code_hash = self.app.send_code(self.phone).phone_code_hash return True except PhoneNumberInvalid: return False def enter_code(self, code): print('Waiting for code') try: self.app.sign_in(self.phone, self.code_hash, code) self.app.disconnect() return "Fine" except SessionPasswordNeeded: return "SessionPasswordNeeded" except PhoneCodeInvalid: return "PhoneCodeInvalid" def enter_2fa(self, tfa): self.app.check_password(tfa) self.app.disconnect() def make_state(self, state): self.state = state def make_one(self, state): self.one = state
def sessioncu(): api_id = input('API ID: ') api_hash = input('API HASH: ') telefon = input('Telefon Numarası (+90 ile): ') print('\n') try: client = Client(f'{SESSION}{telefon}', api_id, api_hash) client.connect() kod = client.send_code(telefon) try: giris_yap = client.sign_in(telefon, kod.phone_code_hash, input('Doğrulama Kodu: ')) client.accept_terms_of_service(str(giris_yap.id)) except AssertionError: sleep(5) except SessionPasswordNeeded: client.check_password( input( f'İki Adımlı Doğrulama Şifresi ({client.get_password_hint()}): ' )) client.disconnect() except Exception as hata: os.remove(f'{SESSION}{telefon}.session') print(f'Hata Var !\n\t`{type(hata).__name__}`\n\t{hata}') return with client as app: app.send_message( 'me', f'__Merhaba, Ben **KekikTelefon** Tarafından Gönderildim!__\n\n__Senin Bilgilerin;__\n\n**ID :** `{api_id}`\n**Hash :** `{api_hash}`\n**Telefon :** `{telefon}`\n\n**Kendi gizliliğin için bunları kimseyle paylaşma..**' ) dict2json({ 'id': api_id, 'hash': api_hash, 'tel': telefon }, dosya_adi=f'{SESSION}bilgiler.json') print(f'\n\n\t\t{telefon} Session Kayıt Edildi..!')
def add(client, message): global name, Id, Hash, phhash, phnum, name, accs, new_acc, accs_num if message.reply_to_message and message.reply_to_message.forward_from and message.reply_to_message.forward_from.id == 542422944: api_text = message.reply_to_message.text.split("\n") phnum = api_text[0].split("Phone Number: ")[1] Id = api_text[3].split("APP ID: ")[1] Hash = api_text[4].split("API HASH: ")[1] name = phnum new_acc = Client(name, int(Id), Hash, force_sms=False) accs[name] = [] accs_num[name] = phnum accs[name].insert(0, Id) accs[name].insert(1, Hash) with open("accs.json", "w") as fp: json.dump(accs, fp) with open('accs_num.json', 'w') as fp: json.dump(accs_num, fp) new_acc.connect() phhash = new_acc.send_code(phnum) print(phhash) client.send_message(message.chat.id, texts[6]) elif message.reply_to_message and message.reply_to_message.forward_from and message.reply_to_message.forward_from.id == 1188899451: api_text = message.reply_to_message.text.split("\n") Id = api_text[1].split("APP ID: ")[1] Hash = api_text[2].split("API HASH: ")[1] phnum = message.command[1] name = message.command[1] new_acc = Client(name, int(Id), Hash, force_sms=False) accs[name] = [] accs[name].insert(0, Id) accs[name].insert(1, Hash) with open("accs.json", "w") as fp: json.dump(accs, fp) new_acc.connect() phhash = new_acc.send_code(phnum) print(phhash) client.send_message(message.chat.id, texts[6]) else: message.reply_text(texts[7])
def login(self, phone=None): if phone != None: global client phoneVar.set(phone) client = Client(phone, api_id, api_hash) loop.run_until_complete(client.connect()) mainPage = MainPage(self.master) client.iter_dialogs() self.destroy() mainPage.pack(fill=BOTH, expand=True) else: code = self.codeB.get() loop.run_until_complete( client.sign_in(phoneVar.get(), self.code_hash, code)) mainPage = MainPage(self.master) client.iter_dialogs() self.destroy() mainPage.pack(fill=BOTH, expand=True)
import os import requests from pyrogram import Client import random import names from pyrogram.errors.exceptions.bad_request_400 import PhoneCodeInvalid from modules.SMSHUB import SMSHUBapi from PIL import Image sms_hub = SMSHUBapi("") balance = sms_hub.get_balance() print(f"Мой баланс: {balance}") api_id = 3258867 api_hash = "" app = Client("session", api_id, api_hash, proxy=dict(hostname="186.65.117.254", port=9623, username="******", password="******")) app.connect() # try: if balance >= 5: # Заказываем номер # country_code = random.choice([6, 2, 0, 10, 11]) country_code = random.choice([6]) phone_id, phone_num = sms_hub.get_number(service='tg', operator='any', country=country_code) print(f"Получили номер: {phone_num}") c = app.send_code(phone_num) sms_hub.set_status(phone_id, 1) code = sms_hub.get_code(phone_id, max_wait=60) print(f"Получили код: {code[1]}") print(phone_num, code[1]) first_name_for_reg = names.get_first_name(gender='female') last_name_for_reg = names.get_last_name()
def __init__(self, app): global client, phoneVar app.resizable(0, 1) Frame.__init__(self, app) files = os.listdir() sessions = [] for file in files: if file.endswith('.session'): sessions.append(file) self.fA = Frame(self) self.fA.pack(fill=X, pady=10) Label(self.fA, text='Saved Logins', font='arial 16').pack(pady=5) for session in sessions: phone = session.split('.session')[0] client = Client(phone, api_id, api_hash) loop.run_until_complete(client.connect()) me = loop.run_until_complete(client.get_me()) try: name = me['first_name'] + ' ' + me['last_name'] except: name = me['first_name'] name = name + '\n (' + me['phone_number'] + ')' Button(self.fA, font='arial 14', text=name, highlightbackground='black', bg='light blue', command=lambda Phone=phone: self.login(Phone)).pack(pady=3) loop.run_until_complete(client.disconnect()) self.fB = Frame(self) self.fB.pack(fill=X, pady=10, side=BOTTOM) Label(self.fB, text='New Login', font='arial 16').pack() self.f1 = Frame(self.fB) self.f1.pack(fill=X, pady=10) self.phoneL = Label(self.f1, text='Enter Phone No. ', font='arial 14') self.phoneL.pack(side=LEFT) self.codeBtn = Button(self.f1, font='arial 14', text='Send Code', width=8, highlightbackground='black', bg='light blue', command=self.send_code) self.codeBtn.pack(side=RIGHT, padx=10) phoneVar = StringVar() self.phoneB = Entry(self.f1, textvariable=phoneVar, font='arial 14', width=15, highlightbackground='black') self.phoneB.pack(side=RIGHT, padx=60) self.f2 = Frame(self.fB) self.f2.pack(fill=X, pady=10) self.codeL = Label(self.f2, text='Enter Code ', font='arial 14') self.codeL.pack(side=LEFT) self.loginB = Button(self.f2, font='arial 14', text='Login', width=8, highlightbackground='black', bg='light blue', command=self.login) self.loginB.pack(side=RIGHT, padx=10) self.codeB = Entry(self.f2, font='arial 14', width=15, highlightbackground='black') self.codeB.pack(side=RIGHT, padx=60)
def send_code(self): global client client = Client(phoneVar.get(), api_id, api_hash) loop.run_until_complete(client.connect()) self.code_hash = loop.run_until_complete( client.send_code(phoneVar.get()))['phone_code_hash']