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
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 # 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)
Hostname: www.google.com and IP: 126.96.36.199
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!