ipme.sh

Your IP address, and a free API to get it

See your public IPv4 and IPv6 address, then fetch it from any script with one request. Plain text or JSON, no sign-up, no API key.

Live, from your connection
$ curl https://api.ipme.sh
Checking…

$ curl https://api.ipme.sh/json
{"ip":"…"}
IPv4
Checking…
IPv6
Checking…

Endpoints

The subdomain picks IPv4 or IPv6. The path picks the format.

HostForces
api.ipme.shIPv4 or IPv6 (whichever the client uses)
ipv4.api.ipme.shIPv4 only (DNS has no AAAA record)
ipv6.api.ipme.shIPv6 only (DNS has no A record)
PathContent-TypeExample body
/ or /ip text/plain 203.0.113.42
/json application/json {"ip":"203.0.113.42"}
/jsonp?callback=cb application/javascript cb({"ip":"203.0.113.42"})
/healthz (none) 200 OK

JSONP callbacks should be valid JavaScript identifiers. Anything else comes back as a 400.

Examples

cURL
# Default (whichever family resolves first)
curl https://api.ipme.sh

# Force IPv4 / IPv6 via DNS-only subdomains
curl https://ipv4.api.ipme.sh
curl https://ipv6.api.ipme.sh

# JSON
curl https://api.ipme.sh/json
JavaScript (browser fetch)
const r = await fetch('https://api.ipme.sh/json');
const { ip } = await r.json();
console.log(ip);
Python
import urllib.request, json

with urllib.request.urlopen('https://api.ipme.sh/json') as r:
    print(json.load(r)['ip'])

# or with requests
import requests
print(requests.get('https://api.ipme.sh').text.strip())
Go
package main

import (
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    r, _ := http.Get("https://api.ipme.sh/json")
    defer r.Body.Close()
    var out struct{ IP string }
    json.NewDecoder(r.Body).Decode(&out)
    fmt.Println(out.IP)
}
Node.js
const r = await fetch('https://api.ipme.sh/json');
const { ip } = await r.json();
console.log(ip);
Bash (dynamic DNS pattern)
#!/usr/bin/env bash
# Update record only when public IP changes.
set -euo pipefail

STATE=/var/lib/ipme/last-ip
mkdir -p "$(dirname "$STATE")"
NOW=$(curl -fsS https://api.ipme.sh)
LAST=$(cat "$STATE" 2>/dev/null || true)

if [[ "$NOW" != "$LAST" ]]; then
  echo "IP changed: $LAST -> $NOW"
  # update_dns_record "$NOW"
  echo "$NOW" > "$STATE"
fi
PHP
$ip = trim(file_get_contents('https://api.ipme.sh'));
echo $ip;

// JSON
$data = json_decode(file_get_contents('https://api.ipme.sh/json'), true);
echo $data['ip'];
Ruby
require 'net/http'
require 'json'

ip = Net::HTTP.get(URI('https://api.ipme.sh')).strip
puts ip

data = JSON.parse(Net::HTTP.get(URI('https://api.ipme.sh/json')))
puts data['ip']
Rust (ureq)
let ip: String = ureq::get("https://api.ipme.sh")
    .call()?
    .into_string()?
    .trim()
    .to_string();
println!("{ip}");
Java
// Java 11+
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class IpMe {
    public static void main(String[] args) throws Exception {
        var client = HttpClient.newHttpClient();
        var req = HttpRequest.newBuilder(URI.create("https://api.ipme.sh")).build();
        var res = client.send(req, HttpResponse.BodyHandlers.ofString());
        System.out.println(res.body().trim());
    }
}
Kotlin (OkHttp)
// build.gradle.kts: implementation("com.squareup.okhttp3:okhttp:4.12.0")
import okhttp3.OkHttpClient
import okhttp3.Request

val client = OkHttpClient()
val req = Request.Builder().url("https://api.ipme.sh").build()
client.newCall(req).execute().use { res ->
    println(res.body!!.string().trim())
}

For server-side Kotlin on JVM 11+, the stdlib java.net.http.HttpClient works without OkHttp. See the Java example above.

Swift (URLSession)
// iOS 15+ / macOS 12+, Swift 5.5+ (async/await)
import Foundation

struct IpResponse: Decodable { let ip: String }

let url = URL(string: "https://api.ipme.sh/json")!
let (data, _) = try await URLSession.shared.data(from: url)
let ip = try JSONDecoder().decode(IpResponse.self, from: data).ip
print(ip)
C# / .NET
// .NET 6+ (top-level statements)
using System.Text.Json;

using var http = new HttpClient();

// Text
var ip = (await http.GetStringAsync("https://api.ipme.sh")).Trim();
Console.WriteLine(ip);

// JSON
using var stream = await http.GetStreamAsync("https://api.ipme.sh/json");
var doc = await JsonDocument.ParseAsync(stream);
Console.WriteLine(doc.RootElement.GetProperty("ip").GetString());
PowerShell
# Text
(Invoke-WebRequest https://api.ipme.sh).Content.Trim()

# JSON (Invoke-RestMethod auto-parses)
(Invoke-RestMethod https://api.ipme.sh/json).ip

# Force IPv4 / IPv6 via DNS-only subdomains
(Invoke-RestMethod https://ipv4.api.ipme.sh/json).ip
(Invoke-RestMethod https://ipv6.api.ipme.sh/json).ip
Elixir (Req)
# mix.exs: {:req, "~> 0.5"}
# or one-off: Mix.install([:req])

# Text
Req.get!("https://api.ipme.sh").body |> String.trim() |> IO.puts()

# JSON (Req auto-decodes application/json)
Req.get!("https://api.ipme.sh/json").body["ip"] |> IO.puts()
JSONP (legacy cross-origin)
<script src="https://api.ipme.sh/jsonp?callback=showIP"></script>
<script>
  function showIP(data) { console.log(data.ip); }
</script>

For anything new, fetch is a better fit. JSONP is mostly for older clients.

Questions

What is my IP address?

It's the address the rest of the internet sees when you connect. The box at the top of this page shows yours, and checks your IPv4 and IPv6 addresses separately so you can see both.

How do I get my public IP from the command line?

Run curl https://api.ipme.sh and it prints your IP as plain text. Add /json to the URL if you'd rather have JSON.

How can I check whether I have IPv6?

Run curl https://ipv6.api.ipme.sh. That host only has an IPv6 address, so if you get an answer, your IPv6 works. ipv4.api.ipme.sh does the same for IPv4.

Is it free? Do I need an API key?

It's free, and there's nothing to sign up for. No account, no API key. Just call it.

Are there rate limits?

Each IP can make up to 20 requests a second and 600 a minute. Go past that and you'll get a 429 for a moment. For things like dynamic DNS, checking once a minute is plenty.

Can I call the API from a web page?

Yes. The API sends open CORS headers, so fetch works from any site. JSONP is there too for older code.

Do you track me?

No cookies, analytics or ad scripts, on this site or in the API.