windows - Python 3 - tkinter , ignore socket.herror and continue -
i try resolve hosts using socket module via gui made using tkinter here part of code , main issue error receive while resolving routers name
for line in p.stdout: fiw = open("1.txt", '+a') line = str(line) if "received = 1" in line: hostad = socket.gethostbyaddr(ip3 +str(i)) if hostad: try: print(hostad) except socket.herror: print(hostad) fiw.write("received reply " + ip3 +str(i)+"\n") print("received reply " + ip3 +str(i)+"\n") print(socket.gethostbyaddr(ip3 +str(i)))
the error :
socket.herror: [errno 11004] host not found
script won't run further used print
here example tried pass
tried
except socket.herror err: print(err) pass
also tried using pass
in method
you have try ... except around wrong thing, instead of
hostad = socket.gethostbyaddr(ip3 +str(i)) if hostad: try: print(hostad) except socket.herror: print(hostad)
it should
try: hostad = socket.gethostbyaddr(ip3 +str(i)) print(hostad) except socket.herror: pass # code execute in case of error
the error message refers "reverse dns lookup failure" explained in python sockets: gethostbyaddr : reverse dns lookup failure
if hostname formed in line
hostad = socket.gethostbyaddr(ip3 +str(i))
does not have reverse dns record, exception thrown.
Comments
Post a Comment