How to get IP Address of Website using Python?

Madhu Sri Sushmitha Chowdary
1 min readDec 6, 2020

--

Python has many inbuilt libraries available for us to make our work more easier. One of the module in Python is socket which is a way of connecting two nodes on a network to communicate with each other.

Sockets and the socket API are used to send messages across a network. They provide a form of Inter Process Communication.

We use the socket function available in socket module to create a socket object. A socket object is then used to call other functions to setup a socket server. Now call bind(hostname, port) function to specify a port for your service on the given host.

Now lets start our program to get IP Address of any Website in just 3 Steps…..

Step 1 : Import Socket module

import socket

Step 2 : Declare a variable with the domain of the Website for which we want IP Address.

host = "www.linkedin.com"

Step 3 : Now print the IP Address of the Website required by considering {socket.gethostbyname(host)} as parameter to print statement.

print(f'IP of {host} is {socket.gethostbyname(host)}')

Now We can get IP of any Website by just changing the domain address of the Website as shown below….

Output :

IP of www.facebook.com is 69.171.250.35IP of www.instagram.com is 69.171.250.174IP of www.medium.com is 104.16.120.145IP of www.twitter.com is 104.244.42.193

Happy Coding 😁😁

--

--

No responses yet