I am trying to reverse dns a list of IPs using socket.gethostbyaddr() in python, which returns 'Unknown Host' for some values, but using dig for the same ip returns the Hostname. Also, dig seems to be significantly faster than using python module, is there any specific reasons for that?
import socket
# This returns 'Unknown Host'
name, alias, addresslist = socket.gethostbyaddr('114.143.51.197')
From the comments...
I'm sorry, but you are mistaken. 114.143.51.197 does not have a PTR record... therefore
socket.gethostbyaddr()should throw an error... To process this use-case correctly, add atry/exceptclause that trapssocket.herrorDNS reverse lookup for 114.143.51.197... note that it does not have a valid
PTRrecordThis is what a valid
PTRrecord should look like...