No Result
View All Result
DevRescue
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us
DevRescue
Home Blog Python

Python Reverse DNS Lookup

by Khaleel O.
January 9, 2022
in Python
Reading Time: 3 mins read
A A
Python Reverse DNS Lookup
Python Reverse DNS Lookup

Hi! Let’s use Python to do a Reverse DNS Lookup! We will be using Python 3.8.10. Let’s go! ⚡✨

With a reverse DNS lookup, you already have the IP address and you want to find the associated domain name. It is the opposite of the usual DNS Lookup or Query where you have the domain name and wish to find the IP. Let’s write some code:

import dns.resolver, dns.reversename

addrs = dns.reversename.from_address("8.8.8.8")

print(str(dns.resolver.resolve(addrs,"PTR")[0]))

#output
#dns.google.
  1. First we import the dnspython library. If you don’t have it installed you can use the pip install dnspython command to install it. The dnspython library gives us powerful tools with which to achieve DNS operations, including our reverse DNS lookup.
  2. We import two methods that we will use: dns.resolver and dns.reversename.
  3. The dns.reversename.from_address method converts an IPv4 or IPv6 address into a name object of class dns.name.Name. We must supply the string literal IP address that we want to lookup as the parameter text. In this case we are using “8.8.8.8”. It returns a name object which we store as addrs.
  4. The dns.resolver.resolve method will actually query the nameserver of the domain for the domain name. In this case, we supply two parameters: qname and rdtype. The qname in this case is the name object addrs that we retrieved in the previous line. The rdtype is the record type we want which is the “PTR” record on this occasion. This method will return a dns.resolver.Answer list object that will contain the domain name we seek. We use the index 0 for this example because we want to retrieve the first element of this dns.resolver.Answer object.

Easy right? When the code executes we should get a proper domain name printed to the screen.

The ‘PTR’ or DNS Pointer record exists for security purposes. The mail server uses the ‘PTR’ record to check that the mail server that’s sending the mail matches its proper IP address as opposed to being from a fraudulent domain. The ‘PTR’ record has the genuine domain name that matches our IP address.

Thanks for reading our Python Reverse DNS Lookup tutorial. Find the complete dnspython documentation HERE.

Also find a tutorial on doing a classic DNS lookup (using a domain or machine name) HERE.


Are you worried about your child’s online safety or your employees’ productivity? Do you wonder what they’re accessing on their devices? SentryPC is here to address these concerns. This all-in-one, cloud-based software provides robust activity monitoring, content filtering, and time management, making it ideal for both parental control and employee monitoring. Embrace peace of mind and enhanced efficiency with SentryPC, the proactive solution to your digital monitoring needs. CLICK HERE to get started.

Tags: dnspythonnetworking
Previous Post

Python dnspython Introduction

Next Post

Insertion Sort Python Explained

Khaleel O.

Khaleel O.

I love to share, educate and help developers. I have 14+ years experience in IT. Currently transitioning from Systems Administration to DevOps. Avid reader, intellectual and dreamer. Enter Freely, Go safely, And leave something of the happiness you bring.

Related Posts

Python

Python Fibonacci Recursive Solution

by Khaleel O.
January 16, 2024
0
0

Let's do a Python Fibonacci Recursive Solution. Let's go! 🔥🔥🔥 The Fibonacci sequence is a series of numbers in which...

Read moreDetails
Python

Python Slice String List Tuple

by Khaleel O.
January 16, 2024
0
0

Let's do a Python Slice string list tuple how-to tutorial. Let's go! 🔥🔥🔥 In Python, a slice is a feature...

Read moreDetails
Python

Python Blowfish Encryption Example

by Khaleel O.
January 14, 2024
0
0

Let's do a Python Blowfish Encryption example. Let's go! 🔥 🔥 Blowfish is a symmetric-key block cipher algorithm designed for...

Read moreDetails
Python

Python Deque Methods

by Khaleel O.
January 14, 2024
0
0

In this post we'll list Python Deque Methods. Ready? Let's go! 🔥🔥🔥 A deque (double-ended queue) in Python is a...

Read moreDetails

DevRescue © 2021 All Rights Reserved. Privacy Policy. Cookie Policy

Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Manage your privacy
To provide the best experiences, DevRescue.com will use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
No Result
View All Result
  • Home
  • Python
  • Lists
  • Movies
  • Finance
  • Opinion
  • About
  • Contact Us

DevRescue © 2022 All Rights Reserved Privacy Policy