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
| Endpoint | Returns |
|---|---|
GET https://ip-facts.com/ip.txt | Your IP address as plain text, followed by a newline. |
GET https://ip-facts.com/api/ip | JSON: {"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
- Up to 60 requests per minute per IP address. Beyond that you'll get
429 Too Many Requestswith aRetry-Afterheader. - Responses are never cached (
Cache-Control: no-store), so you always get your current address. - If you poll, once every few minutes is plenty for detecting an IP change.
- No API key or sign-up is needed. Please follow our terms of use.
Need location data?
The API only returns your address. For location, ISP and ASN, use the IP lookup tool.