Python 3 Script to Get IP Address and Hostname of Website URL Using Socket Library Full Project For Beginners

Python 3 Script to Get IP Address and Hostname of Website URL Using Socket Library Full Project For Beginners

 

Welcome folks today in this post we will be getting ip address and hostname of website url in python using socket library. All the full source code of application is given below.

 

 

Get Started

 

 

In order to get started you need to create an app.py file and copy paste the following code

 

app.py

 

 

# importing socket library
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()

 

 

Now we can run this app.py python script using the below command

 

python app.py

 

 

 

 

As you can see we are providing the website url as www.freemediatools.com and then it has gave me the ip address and hostnmame of this website

See also  Python 3 Tkinter Take Input From Entry Box With Placeholder Text GUI Desktop App Full Project For Beginners

 

Leave a Reply