Make an IP finder using python 3

Welcome Everyone, in today’s tutorial I will be teaching you how to make an IP finder using socket in Python.

To start, fire up Pycharm and create a new file for this tutorial I named my file “IP”.
next, we should import the socket module by adding the following to line 1:

Import socket

This allows us to access defines for the socket module.

I usually start my programs with a statement using the input function.

My statement for this program would be “Enter the URL for the site you want the IP of”, to set this as input I would type this:

websiteIP = input("Enter the URL for the site you want the IP of: ")

This tells the computer that the string named "websiteIP" is the URL. Now lets find the IP,
This is where the socket module comes in, enter the following:

ip = socket.gethostbyname(websiteIP


This tells the computer to find the IP using the string (Where we input the URL) and then 
attaches itself to the string ip (To make it easier for us to call). After that, type the following:


print("The IP for", websiteIP, "is: ", ip)
input("Press Enter to Continue...")



This will now print out the ip of the website, I usually add a "Press Enter to Continue" as it makes
it easier in the long run when you run it through a terminal.


In the end all of your code should look soemthing like this:

import socket

websiteIP = input("Enter the URL for the site you want the IP of: ")
ip = socket.gethostbyname(websiteIP)
print("The IP for", websiteIP, "is: ", ip)
input("Press Enter to Continue...")



Thank you for reading this tutorial, If you have any questions feel free to leave a comment.


pentester

Leave a Reply