uh hello guys uh welcome to this video
so in this video I will show you how to
return the information about a specific
IP address inside your Python script so
this Python script will actually take an
IP
address and return the information about
that IP address you can track where this
IP address is located the country or
region everything so if I just
uh execute this script you will see the
IP details saved to so this CSV file is
generated and you can see we inputed
this IP address which is
172 and this details are submitted you
will see the region is Oakuckland New
Zealand you will see the location
latitude longitude everything is written
the full address time zone as
well so there is a package here inside
Python which returns all this
information for completely free we are
not using any sort of API key you can do
this unlimited number of times for
completely free so the name of the API
is IP
info this is a free API which doesn't
cost you money if you go to this if you
go to the pricing of this API you will
see unlimited request you can
make $0 per month so don't need to
provide any API key and uh you simply
hit this API and it will return you the
response so let me show you the script
the full script is given in the
description of this video so first of
all we need the request module and also
the CSV module as well then we
simply specify the IP
address which you want to get the
information so you input your IP
address and then you simply call this
function get IP info i will define this
and pass the IP address as an
argument so now we just need to define
this custom function which is get IP
info so inside this function we just
need to make a simple rest API call to
this API which is
HTTPS IP info.io
IO and here we specify our IP
address so dollar is not
necessary and
/json so this will return a JSON
response to us so we just just need to
ex parse it so inside the request module
we get this get method to send this API
request and now the response will be
coming so if the status code is 200 then
the request is successful then we simply
need to convert this response to JSON we
can do this and
then in the else case we can return none
that's all so it will return you the
response in a JSON
format and then we can simply save
this after we get this we can have a if
condition that if info is defined then
we need to save this to
CSV and then we can see IP information
has been saved so now we just need to
define this function save to CSV which
will actually carry out the process for
saving the data
so it will have the
actual data and the file
name then we simply use the open
function we simply open the file name in
the write
mode and then the new line will be
nothing
and encoding you can provide UTF8
and then uh for writing the CSV file we
simply use
the CSV writer class so CSV it contains
this function dictionary writer and here
we specify the file and the field names
which is data
keys and then we call this function
write
header and then writer dot write
row so this completes your script that's
all that is required for this
application let me delete this file once
again run the Python
script so you can see it
will return you the data here you can
take any IP address it will return you
the CSV file holding all this data for
us so let me verify my IP address so I
will go to what is my IP address
so as you can see this is my IP address
so I copy
this so you'll see this website is
returning all this
information so if I input
this IP
address so let me run this script now
for this IP
address so if you open this your CSV
file you will
see it is returning the correct address
you will see the latitude longitude the
ISP provider everything has been
successfully returned with the correct
information so in this way you can track
any IP address inside Python using this
uh API IP info please hit the like
button subscribe the channel and also
check out my website freemediattools.com
uh which contains thousands of tools