Getting Started
ipdata provides a JSON IP Address Geolocation API that allows you to lookup the location of any IP address, both IPv4 and IPv6.
Make sure to sign up for a Free API key here to test these examples.
The simplest call you can make would be a parameter-less GET call to the API endpoint at https://api.ipdata.co. This would return the location of the calling IP address.
1
curl "https://api.ipdata.co?api-key=test"
Copied!
To lookup a specific IP Address
1
curl "https://api.ipdata.co/8.8.8.8?api-key=test"
Copied!

More Examples

Javascript
Python
Node
PHP
Ruby
Go
C#
Java
Swift
1
var request = new XMLHttpRequest();
2
3
request.open('GET', 'https://api.ipdata.co/?api-key=test');
4
5
request.setRequestHeader('Accept', 'application/json');
6
7
request.onreadystatechange = function () {
8
if (this.readyState === 4) {
9
console.log(this.responseText);
10
}
11
};
12
13
request.send();
Copied!
1
from ipdata import ipdata
2
from pprint import pprint
3
4
# Create an instance of an ipdata object. Replace `test` with your API Key
5
ipdata = ipdata.IPData('test')
6
response = ipdata.lookup('69.78.70.144')
7
pprint(response)
Copied!
1
import IPData from 'ipdata';
2
3
const ipdata = new IPData('test');
4
5
const ip = '1.1.1.1';
6
ipdata.lookup(ip)
7
.then(function(data) {
8
console.log(data)
9
});
Copied!
1
use Ipdata\ApiClient\Ipdata;
2
use Symfony\Component\HttpClient\Psr18Client;
3
use Nyholm\Psr7\Factory\Psr17Factory;
4
5
$httpClient = new Psr18Client();
6
$psr17Factory = new Psr17Factory();
7
$ipdata = new Ipdata('test', $httpClient, $psr17Factory);
8
$data = $ipdata->lookup('69.78.70.144');
9
echo json_encode($data, JSON_PRETTY_PRINT);
Copied!
1
require 'uri'
2
require 'net/http'
3
4
url = URI("https://api.ipdata.co/?api-key=test")
5
6
http = Net::HTTP.new(url.host, url.port)
7
8
request = Net::HTTP::Get.new(url)
9
10
response = http.request(request)
11
puts response.read_body
Copied!
1
package main
2
3
import (
4
"github.com/ipdata/go"
5
"log"
6
"fmt"
7
)
8
9
func main() {
10
ipd, _ := ipdata.NewClient("test")
11
data, err := ipd.Lookup("8.8.8.8")
12
if err != nil {
13
log.Fatalf("%v", err)
14
}
15
16
fmt.Printf("%s (%s)\n", data.IP, data.ASN)
17
}
Copied!
1
var client = new IpDataClient("test");
2
3
// Get IP data from IP
4
var ipInfo = await client.Lookup("8.8.8.8");
5
Console.WriteLine(quot;Country name for {ipInfo.Ip} is {ipInfo.CountryName}");
Copied!
1
import io.ipdata.client.Ipdata;
2
3
URL url = new URL("https://api.ipdata.co");
4
IpdataService ipdataService = Ipdata.builder().url(url)
5
.key("test").get();
6
IpdataModel model = ipdataService.ipdata("1.1.1.1");
7
System.out.println(jsonSerialize(model));
Copied!
1
import Foundation
2
3
let request = NSMutableURLRequest(url: NSURL(string: "https://api.ipdata.co/?api-key=test")! as URL,
4
cachePolicy: .useProtocolCachePolicy,
5
timeoutInterval: 10.0)
6
request.httpMethod = "GET"
7
8
let session = URLSession.shared
9
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
10
if (error != nil) {
11
print(error)
12
} else {
13
let httpResponse = response as? HTTPURLResponse
14
print(httpResponse)
15
}
16
})
17
18
dataTask.resume()
Copied!
All calls must be made to the https endpoint. No requests will be served over unsecured HTTP.
The test API key used in these examples is very heavily rate limited do not use it for anything you care about.

What's next?

Last modified 10mo ago
Copy link