In this article we are going to learn about the various methods of getting a person’s ip address using python and also using this ip address to find the location of a person. Let us get started.
We are going to use the requests module in python to get all these data.
What is request module in python?
requests module allows you to send HTTP requests like GET, POST, PUT and DELETE using Python. We are only going to use the get method to hit an url and get the response data
1. From “ipify.org”
The following url “https://api.ipify.org” returns the ip address of the user. This is how we execute the code in python.
But this url does not provide any further informations like address, state and country etc.
2. From “amazonaws.com”
The amazon aws also has a url called “https://checkip.amazonaws.com” which will also return only the ip to the user. This will work even when connected to a VPN.
3. From “ipinfo.io”
This is the best site to get all data other than our ip address. This site provides the following informations.
- ip address
The following code snippet will show you how to get the above informations from this site.
This code will return the following output.
ip: "18.104.22.168" city: "New York City" region: "New York" country: "US" postal: "10004" timezone: "America/New_York"
They also have a python package but you may have to create an account to get the access keys. Hope this article was useful.