Loop to find correct combination

Asked

Viewed 54 times

-3

I recently built a simple algorithm to find correct combinations with the following url:

https://api-main.ecobonuz.com/api/v1/bus-cards/checkInfo?number=1395037673&card=5c8b1160a453ea0ae5e0fdfd&busCardId=&checkBusCard=true&ein= 

I needed the parameter number began in 1000000000 and were up 9000000000. If the status code is 200 or True, would like to store the number used in the request.

For now I have only this code:

import requests 
import json

numero=

Url='https://api-main.ecobonuz.com/api/v1/bus-cards/checkInfo?number='+numero+'&card=5c8b1160a453ea0ae5e0fdfd&busCardId=&checkBusCard=true&ein='

r = requests.get(Url)

print(r.text) 

I am a beginner so if there was any mistake, please let me know the problems to enrich my learning.

  • 2

    you want to make 8 billion http requests, that’s it?

2 answers

-1

Welcome to Stack Overflow, Jacksuel!

import requests 
import json

codigos=[] # lista vazia que armazenará os códigos

for i in range(1000000000, 9000000001): # loop entre os números pretendidos
    url=f'https://api-main.ecobonuz.com/api/v1/bus-cards/checkInfo?number={i}&card=5c8b1160a453ea0ae5e0fdfd&busCardId=&checkBusCard=true&ein=' # cria o URL com o número que o loop está a processar
    r = requests.get(url)
        if r.status_code == 200: # se a resposta for 200...
            codigos.append(i) # adiciona o número (i.e. 1000000006) à lista "códigos"
  • Please Carlos, don’t just put the solution code in the answer. Explain what you did so that the author of the question and others can understand.

  • @Jeanextreme002 commented on the code, friend! But I saw your answer and I understood. Thank you!

-1


To perform multiple requests by changing the value of number between X and Y, just scroll through the numbers inside a loop for using the function range (returns numbers between X and Y) and then send the request.

url = 'https://api-main.ecobonuz.com/api/v1/bus-cards/checkInfo?number={}&card=5c8b1160a453ea0ae5e0fdfd&busCardId=&checkBusCard=true&ein='

for number in range(1000000000, 9000000001):
     response = requests.get(url.format(number))

One improvement you can make in your code is to create a dictionary to store all parameters passed in the request separately.

This way, your code will be much more organized.

params = {
    'number': None,
    'card': "5c8b1160a453ea0ae5e0fdfd",
    'busCardId': '',
    'checkBusCard': True,
    'ein': ''
    }

url = 'https://api-main.ecobonuz.com/api/v1/bus-cards/checkInfo'

To check if the answer code was 200, just check the attribute status_code with a conditional. If the condition is true, simply add the used number to a list.

if requests.get(url, params = params).status_code == 200:
    numbers.append(number)

See below the full code:

import requests

params = {
    'number': None,
    'card': "5c8b1160a453ea0ae5e0fdfd",
    'busCardId': '',
    'checkBusCard': True,
    'ein': ''
    }

url = 'https://api-main.ecobonuz.com/api/v1/bus-cards/checkInfo'

start = 1000000000
stop = 9000000000

numbers = []

for number in range(start, stop + 1):

    params["number"] = number
    response = requests.get(url, params = params)

    if response.status_code == 200:
        numbers.append(number)
        print("Número encontrado:", number)
  • 2

    I don’t know how didactic it is to teach someone who doesn’t even know how to use a variable that’s all right to make a brute case attack against an API, trying to make 8 billion requests - even if each request takes 20 seconds, that would be about 10 years - then it has to be didactic as well and explain the issue of computational and network resources, and the ethical issues of trying to guess discount codes by brute force. I would recommend addressing these points in your reply.

  • You’re right, I read the question but I didn’t touch on what it was trying to do. The site prohibits this kind of question here ?

  • 1

    I think it is forbidden is not - will each one know how to answer even - if it is really an explicit crime, then it is against the law - and do not carry the rules of the site. In this case, the person is only with the intention, but wants to try - I think it is worth just calling attention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.