ip-facts

IP address API

Get your public IP address as plain text or JSON with a single HTTP request. Free, no key required, CORS enabled.

Endpoints

EndpointReturns
GET https://ip-facts.com/ip.txtYour IP address as plain text, followed by a newline.
GET https://ip-facts.com/api/ipJSON: {"ip": "…", "version": 4}. version is 4 or 6.

The address returned is the one your request arrived from. If your network has both IPv4 and IPv6, your client decides which one to use; force one with curl -4 or curl -6.

Examples

Shell

curl https://ip-facts.com/ip.txt
curl -s https://ip-facts.com/api/ip
# Force IPv4 or IPv6
curl -4 https://ip-facts.com/ip.txt
curl -6 https://ip-facts.com/ip.txt

JavaScript (browser or Node)

const { ip, version } = await fetch('https://ip-facts.com/api/ip').then((r) => r.json());

Python

import urllib.request, json
data = json.load(urllib.request.urlopen("https://ip-facts.com/api/ip"))
print(data["ip"])

PHP

$ip = trim(file_get_contents('https://ip-facts.com/ip.txt'));

Example response

HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: *
Cache-Control: no-store, private

{"ip":"203.0.113.42","version":4}

Limits and fair use

Need location data?

The API only returns your address. For location, ISP and ASN, use the IP lookup tool.