Skip to content

KHAPCHI.COM

One stick to rule all staffs!

  • Home
  • Technology
  • Tools
  • About
  • Toggle search form
  • Install and configure Squid3 for Ubuntu20.04 for known hosts – IP Access Uncategorized
  • How to Query any REST API using Python3 easy. Technology
  • 7 Commands to know your Linux Server Technology
  • Prepare a Linux server for first use. Technology
  • How to store JSON response from an API to MySQL table? Technology
  • Python3 regular expression to fetch Domains from a string or Paragraph. Technology
  • How to fetch all DNS records of a Domain using Python3. Technology
  • How to connect to Local MySQL Db using Python3 Technology

How to make DNS lookup of an IP or Domain using Python3.

Posted on December 8, 2022December 8, 2022 By Khapchi No Comments on How to make DNS lookup of an IP or Domain using Python3.

To make DNS lookups for a domain or IP using Python3, you can use the socket module, which provides functions for working with network sockets. Specifically, you can use the gethostbyname() and gethostbyaddr() functions to perform DNS lookups for domain names and IP addresses, respectively.

Here is an example of how you might use the gethostbyname() function to look up the IP address associated with a domain name:

import socket

# Look up the IP address for a domain name
ip_address = socket.gethostbyname("www.google.com")
print(ip_address)  # Prints "172.217.17.110"

In this example, we import the socket module and use the gethostbyname() function to look up the IP address for the domain name “www.google.com“. The function returns the IP address as a string, which we print to the console.

To use the gethostbyaddr() function to look up the domain name associated with an IP address, you can use the following code:

import socket

# Look up the domain name for an IP address
domain_name = socket.gethostbyaddr("172.217.17.110")
print(domain_name)  # Prints "google.com"

In this example, we use the gethostbyaddr() function to look up the domain name associated with the IP address “172.217.17.110”. The function returns the domain name as a string, which we print to the console.

Note that these functions can only perform lookups for domain names and IP addresses that are registered with the DNS system. If you try to look up an unregistered domain name or IP address, these functions will return an error.

Technology Tags:Python Socket, Python3

Post navigation

Previous Post: How to connect to Local MySQL Db using Python3
Next Post: How to fetch all DNS records of a Domain using Python3.

Related Posts

  • Store JSON response from API as separate columns in MySQL table? Technology
  • Multilib problems while using yum. Technology
  • Python3 regular expression to fetch Domains from a string or Paragraph. Technology
  • Prepare a Linux server for first use. Technology
  • How to store JSON response from an API to MySQL table? Technology
  • How to Query any REST API using Python3 easy. Technology

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Recent Posts

  • Python3 regular expression to fetch Domains from a string or Paragraph.
  • Store JSON response from API as separate columns in MySQL table?
  • How to store JSON response from an API to MySQL table?
  • How to Query any REST API using Python3 easy.
  • How to fetch all DNS records of a Domain using Python3.

Recent Comments

    Archives

    • December 2022
    • July 2020
    • May 2020

    Categories

    • Technology
    • Uncategorized

    Archives

    • December 2022
    • July 2020
    • May 2020
    • Prepare a Linux server for first use. Technology
    • How to fetch all DNS records of a Domain using Python3. Technology
    • Install and configure Squid3 for Ubuntu20.04 for known hosts – IP Access Uncategorized
    • Python3 regular expression to fetch Domains from a string or Paragraph. Technology
    • Store JSON response from API as separate columns in MySQL table? Technology
    • How to Query any REST API using Python3 easy. Technology
    • How to store JSON response from an API to MySQL table? Technology
    • 7 Commands to know your Linux Server Technology

    Copyright © 2025 KHAPCHI.COM.

    Powered by PressBook News WordPress theme