Hi, new to Python. Just trying to put together a small script to read a file of IP addresses and resolve to name, write back to file. small tool and learning exercise for me.
import subprocess import socket tstout = open('testout.txt','w+') with open("testip.txt", "r") as ins: for l in ins: out = socket.gethostbyaddr(ins) tstout.write (out) tstout.close() subprocess.Popen([r'c:\Windows\notepad.exe',r'c:\scripts\testout.txt'])
Get traceback “TypeError: gethostbyaddr() argument 1 must be str, bytes or bytearray, not _io.TextIOWrapper”
The file opened for read just has an ip address (v4) in one line, nearest I can read this, the IP address line is not being read as a string variable, is there a way to convert the data as it is being read to str ?
Thanks in advance