Find IP Address of any Website Using Python

Find IP Address of any Website Using Python

Hello world!

IP address helps in connecting our computer to other devices on our network and all over the world. In this Blog article, we will learn how to Find IP Address of any Website. We will see the implementation in Python.

Check out the Repository for Ultimate Resource in python. Drop a star if you find it useful! Got anything to add? Open a PR on the same!

You can refer to my YouTube video Tutorial to see a working tutorial for better Understanding and a step by step Guide of the same.

What will be covered in this Blog

1. What is IP address?
2. Find IP Address of any Website

Let's get started!

What is IP address?:

The Dictionary Defination:

IP address stands for Internet Protocol address, is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication.

IP (Internet Protocol) Address is an address of your network hardware. An IP Address is made up of numbers or characters. All devices that are connected to an internet connection have a unique IP address

There are are two IP versions:

  • IPv4
  • IPv6.

There are a few other types of IP addresses as well like private IP addresses, public IP addresses, static IP addresses and dynamic IP addresses.

If you wish to know more about it, you can refer to IP address Wikipedia Page.

Now that you are familiar with IP address basics, we can move forward to the coding section.

Time to Code!

You can find all the code at my GitHub Repository. Drop a star if you find it useful.

code.png

In order to access the Python library, we need to import the package in our Python script.

import socket as s

We will make use of socket module to get the IP Address of any Website. Now that we have imported it in our python script, let's start by fetching our hostname.

my_hostname = s.gethostname()

We will make use of gethostname method from socket and store it in my_hostname. Let's display our hostname by using print method.

print('Your Hostname is: ' + my_hostname)

#OUTPUT:
--> Your Hostname is: AyushiRawat

Its time to fetch the IP Address. We will make use of gethostbyname method for the same and pass in our hostname, my_hostname. Let's store it in my_ip

my_ip = s.gethostbyname(my_hostname)

Once done, let's display the IP Address.

print('Your Ip Address is: ' + my_ip)

#OUTPUT:
--> Your Ip Address is: 192.168.1.3

Now, let's fetch the IP Address of my blogging webiste, https://ayushirawat.com/. We will store the hostname in host.

host = 'ayushirawat.com'

Let's fetch the IP Address using the gethostbyname method and pass in host.

ip = s.gethostbyname(host)

Finally, let's display the IP Address of my blogging webiste!

print('The IP Address of ' + host + ' is: '  + ip)

#OUTPUT:
--> The IP Address of ayushirawat.com is: 192.241.200.144

With these steps, you can successfully get the IP Address of any website using python. That's it!

Simple, isn't it? Hope this tutorial has helped. I would strongly recommend you to Check out the YouTube video of the same and don't forget to subscribe my Channel.

You can play around with the socket library and even explore more features. You can even make use of Python GUI using Tkinter.

You can find all the code at my GitHub Repository. Drop a star if you find it useful.

Thank you for reading, I would love to connect with you at Twitter | LinkedIn.

Do share your valuable suggestions, I appreciate your honest feedback!

You should definitely check out my other Blogs:

Resources:

See you in my next Blog article, Take care!!

Did you find this article valuable?

Support Ayushi Rawat by becoming a sponsor. Any amount is appreciated!