;

How to Get the IP Address of the Domain Name Using Python


Tutorialsrack 02/09/2020 Python

In this article, you will learn how to get the IP address of the domain name using python. Python has a built-in function that converts the hostname to an IP address without having to use an external program or library. To get the IP address of the hostname, we need to import the python built-in socket module and socket.gethostbyname() function within the socket module to resolve a hostname to an IP address.

Here is the source code of the program to get the IP address of the domain name using Python.

How to Get the IP Address of the Domain Name Using Python
# How to Get the IP Address of the Domain Name Using Python
 
# Import Module
import socket
 
# Get the IP Address of the Domain Name
ip = socket.gethostbyname('www.google.com')
# Print Output 
print('Hostname: www.google.com and IP: ', ip)
Output

Hostname: www.google.com and IP:  172.217.167.4

I hope this article will help you to understand how to get the IP address of the domain name using python.

Share your valuable feedback, please post your comment at the bottom of this article. Thank you!


Related Posts



Comments

Recent Posts
Tags