How to find the IP address of a website in python

0

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.

finding ip address

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:

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.

Post a Comment

0Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !