I have a problem with my python script. When doing a port scanner through an IP range, the range works fine for me, but it doesn't do a scan for each IP and I don't know what's wrong with it. Can someone tell me what's wrong. I've been trying for a few days, but I can't.
The error that comes out is:
Traceback (most recent call last):
File "C:\Users\josep\PycharmProjects\pythonProject2\main.py",
line 11, in result=hola.connect_ex((ip,port))
socket.gaierror: [Errno 11001] getaddrinfo failed
Here is the code I have.
import socket
ip=input("Introduce solo 3 octetos ")
for port in range(80,90):
for i in range(1, 11):
print(f"{ip}.{i}")
hola=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result=hola.connect_ex((ip,port))
if result == 0:
print(f"Disponible -> %s:%s" % (ip, port) + "\n")
else:
print(f"Puerto {port} no abierto \n")
hola.close()
You must specify the full address, 4 octets, in
There you are passing only the three octets that the user entered.
It is also poorly indented; You make the connection once per port, not per (address, port).
The correct code is:
produces: