This blogs describes how to find IP address for a website.
We require socket module and gethostbyname() function to find IP Address of a website. Function takes website name and returns IP address of a website.
In our code, we will ask user to enter website then using gethostbyname() function to find IP address. Function returns gaierror (Get Address Information Error) if it does not find website.
Step 1 Importing socket module
Step 2 Asking user to enter website or url
Step 3 Using gethostbyname() function to find IP address and printing it.
Step 4 Printing error message if website not found
Below is the code
import socket host = input('Please enter website or url: ') try: addr = socket.gethostbyname(host) print('IP Address:',addr) except socket.gaierror: print('Website not found')
Output 1 (Website Found)
Please enter website or url: www.facebook.com IP Address: 184.108.40.206
Output 2 (Website not found)
Please enter website or url: www.loddjjkdj.com Website not found