In this python tutorial, we will create a python program that will help us find the IP address of a website. We will be using socket library. socket library is a built-in library in python, which is used for network-related tasks.
Check out: socket programming in python
find the IP address of a website in python
We have used the socket library in python to find the IP address of a website. to find the ip address of a website you can use the gethostbyname()
function.
Python code to find the IP address of a website
Following is python code that you can run in your ide to find the ip address of a website.
import socket
def get_hostname_IP():
hostname = input("Please enter website address(URL):")
try:
print (f'Hostname: {hostname}')
print (f'IP: {socket.gethostbyname(hostname)}')
except socket.gaierror as error:
print (f'Invalid Hostname, error raised is {error}')
get_hostname_IP()
Related Python Projects:
- send Email in Python
- Extract all links from a website in python
- Add Watermark to an Image in Python
- Random Password Generator
- Convert a json file to a csv file in python
- Write hello world in Python
- Create Analog Clock with Python Turtle Module
- Create an Alarm Clock With Python - Python Project
- Create an Amazing Art With Python Turtle - Pickachu Character
- How to Create Decimal to Binary Converter with tkinter Python
- Python Turtle Project - Create Doraemon Character
Summary and Conclusion
We have seen, how we can use the socket library in python to find the ip address of a host. If you have any questions, please leave them in the comment section.