The IP Lookup API provides location information for any valid IP address. It works with both IPv4 and IPv6 addresses.
https://api.api-ninjas.com/v1/iplookup?address=
Returns the location of the IP address specified. The response contains both the geographical coordinates (latitude/longitude) as well as the city and country.
address
requiredIP Address to query. Must be in the format A.B.C.D
. For example: 73.9.149.180
X-Api-Key
requiredAPI Key associated with your account.
address
The IP address of the query
timezone
The time zone related to the IP address
lat
premium onlyThe latitude coordinate of the IP address location
lon
premium onlyThe longitude coordinate of the IP address location
zip
premium onlyThe ZIP code of the IP address location
city
premium onlyThe city where the IP address is located
region
The region name where the IP address is located. In the United States, this is equivalent to the state.
region_code
The region code of the IP address location. In the United States, this is equivalent to the 2-letter state abbreviation.
country
The name of the country where the IP address is located
country_code
The 2-letter country code of the IP address location
is_valid
The validity status of the IP address
isp
premium onlyThe Internet Service Provider associated with the IP address
https://api.api-ninjas.com/v1/iplookup?address=73.9.149.180
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"is_valid": true,
"country": "United States",
"country_code": "US",
"region_code": "IL",
"region": "Illinois",
"city": "Chicago",
"zip": "60620",
"lat": 41.7405,
"lon": -87.6587,
"timezone": "America/Chicago",
"isp": "Comcast Cable Communications, LLC",
"address": "73.9.149.180"
}
1
2
3
4
5
6
7
8
9
import requests
ip_addr = '73.9.149.180'
api_url = 'https://api.api-ninjas.com/v1/iplookup?address={}'.format(ip_addr)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
print(response.text)
else:
print("Error:", response.status_code, response.text)
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.