4

How can I do reverse DNS lookup using scapy in Python? I look for it in Google but I couldn't find related to this topic.

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
Shnkc
  • 2,108
  • 1
  • 27
  • 35
  • possible duplicate of [Python lookup hostname from IP with 1 second timeout](http://stackoverflow.com/questions/2575760/python-lookup-hostname-from-ip-with-1-second-timeout) – mtrw Aug 16 '12 at 11:31

2 Answers2

10

Reverse DNS is already written into Python's Socket module. Simply use the following:

 >>> import socket
 >>> socket.gethostbyaddr("69.59.196.211")
 ('stackoverflow.com', ['211.196.59.69.in-addr.arpa'], ['69.59.196.211'])

Which was originally posted here, Python lookup hostname from IP with 1 second timeout, by https://stackoverflow.com/users/81179/christophed

Community
  • 1
  • 1
rofls
  • 4,993
  • 3
  • 27
  • 37
  • This is not what I am looking for. How can I do this operaton using scapy in python? – Shnkc Aug 16 '12 at 18:50
  • You should still be able to import the `socket` module and use `socket.gethostbyaddr` while in Scapy. – rofls Aug 16 '12 at 19:38
  • I also doesn't work very well for my case. I generally get the answer 'unknown host' – Shnkc Aug 16 '12 at 19:47
7

Ok. I have found my answerm and I want to share it in here, because someone could look for same thing. One line of code is enough to make a reverse dns query in scapy, which is:

sr1(IP(dst="8.8.8.8")/UDP()/DNS(rd=1,qd=DNSQR(qname="211.196.59.69.in-addr.arpa", qtype='PTR')))
Shnkc
  • 2,108
  • 1
  • 27
  • 35