1
I am trying to create a script that performs connection testing on various hosts and different ports, example:
10.20.20.1,1433
10.30.30.2,1521
10.30.30.3,80
10.20.20.4,443
In the script I open a file with the hosts, then open the file with the ports, and use a for for each item within the file. I’m getting the error screen below:
socket.gaierror: [Errno 11001] getaddrinfo failed
Does anyone know what might be causing this error?
Follows the script:
import socket
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
with open('hosts', 'r') as hosts:
for host in hosts:
with open('ports', 'r') as ports:
for port in ports:
intport = int(port)
location = (host, intport)
result_of_check = a_socket.connect_ex(location)
if result_of_check == 0:
print("Port is open")
else:
print("Port is not open")
a_socket.close()
Which command are you using to run the script? Ports with values lower than 1024 require a privileged user to be able to be instained. Is trying with root user?
– Danizavtz
Oops, all right? The error already appears when running by Pycharm... and Pycharm I run in Adm mode.
– Sabbath Doomicus Metallicus
Check your host files, because I made a modifying to run here using the question data and worked.
– Augusto Vasques