well, that is error because it cannot resolve whatever remote host you pass as argument.
The problem is in the new line char at the end of each line when you read from file. I assume ABC is just placeholder and the file has real hostnames
The problem is in the new line char at the end of each line when you read from file. I assume ABC is just placeholder and the file has real hostnames
import socket def get_host_name_ip(fname): with open(fname, "r") as f: for remote_host in f: remote_host = remote_host.strip() # \n (new line) at the end of the line would cause error even when host exists print(remote_host) try: print(f"And IP address is {socket.gethostbyname(remote_host)}") except socket.gaierror as se: print(f"Not done: {se}") # this will catch error when socket.gethostbyname get_host_name_ip("computers.txt")
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs