IP range scanner con python

Viewed 85

I am stuck in a script that I carry out from an IP SCANN with a fixed port. Let's say, I enter an IP, for example 162.86.0.5 and the SCRIPT makes requests up to the number 162.86.255.255. At home, the request logs each IP, if the IP is online. The script works, but it is very slow, it goes from 1 IP to 1 ... let's say that a process of 500 IPs takes me hours, and I would like to be able to do, for example, scan with loguin 20 IPs per request. As all IPs are different, there is no Banning problem, since it is only done once per request. But I don't know how to make a lot of requests in each attempt. Here the code.

import requests
import colorama
from colorama import Fore, Back, Style
colorama.init(autoreset=True)



ip = input("Ingrese ip a escanear: ")
puerto = input("Ingrese puerto: ")

parte = ip.split(".")
a = "."
parts_0 = parte[0]
parts_1 = parte[1]
parts_2 = int(parte[2])
parts_3 = int(parte[3])

payload = {
    'username': 'username',
    'password': 'password',
    "login_button": 'Login'
}


with open(r"D:\prueba.txt", "w"):
    for n in range(parts_2, 255):
        for x in range(parts_3,255):
            enlace = "http://" + parte[0] + a + parte[1] + a + str(n) + a + str(x) + ":" + puerto + '/login.php'
            print(enlace)
            try:
                with requests.Session() as s:
                    peticion = s.get(enlace)
                    if peticion.status_code == 200:
                        r = s.post(enlace, data=payload)
                        with open(r"D:\prueba.txt", "a+",
                                  encoding="utf8") as panel:
                            with print_look:
                                print(enlace + Fore.GREEN + " Respuesta:" + Fore.GREEN + "EXITO")
                                panel.write(str(enlace))
                                panel.write("\n")

            except:
                pass

Like I said, the SCRIPT works but I need to make it faster, let's say it does 20 or 30 requests per scan.

0 Answers
Related