Want to get started right away? Don't wait, run the code sample below in your terminal and check it out!

$ curl 'https://api.ipify.org?format=json'

Why?

Ever needed to get your public IP address programmatically? Maybe you're provisioning new cloud servers and need to know your IP -- maybe you're behind a corporate firewall and need to tunnel information -- whatever the reason: sometimes having a public IP address API is useful!

You should use ipify because:

  • You can use it without limit (even if you're doing millions of requests per minute).
  • It's always online and available, and its infrastructure is powered by Heroku, which means that regardless of whether the server running the API dies, or if there's an enormous tornado which destroys half of the east coast, ipify will still be running!
  • It works flawlessly with both IPv4 and IPv6 addresses, so no matter what sort of technology you're using, there won't be issues.
  • ipify is completely open source (check out the GitHub repository).
  • No visitor information is ever logged. Period.
  • Lastly, ipify is funded by Randall Degges, so there's no need to worry about the domain name disappearing in three years or anything like that: ipify is here to stay!

API Usage

Using ipify is ridiculously simple. You have three options. You can get your public IP directly (in plain text), you can get your public IP in JSON format, or you can get your public IP information in JSONP format (useful for Javascript developers).

API URI Response Type Sample Output (IPv4) Sample Output (IPv6)
https://api.ipify.org text 98.207.254.136 ?
https://api.ipify.org?format=json json {"ip":"98.207.254.136"} ?
https://api.ipify.org?format=jsonp jsonp callback({"ip":"98.207.254.136"}); ?
https://api.ipify.org?format=jsonp&callback=getip jsonp getip({"ip":"98.207.254.136"}); ?

Examples

This section contains some common usage patterns from a variety of programming languages. Want something included that isn't listed here? Email me!

Bash

#!/bin/bash

ip=$(curl -s https://api.ipify.org)
echo "My public IP address is: $ip"

Python

# This example requires the requests library be installed.  You can learn more
# about the Requests library here: http://docs.python-requests.org/en/latest/
from requests import get

ip = get('https://api.ipify.org').text
print 'My public IP address is:', ip

Ruby

require "net/http"

ip = Net::HTTP.get(URI("https://api.ipify.org"))
puts "My public IP Address is: " + ip

PHP

<?php
    $ip = file_get_contents('https://api.ipify.org');
    echo "My public IP address is: " . $ip;
?>

Java

try (java.util.Scanner s = new java.util.Scanner(new java.net.URL("https://api.ipify.org").openStream(), "UTF-8").useDelimiter("\\A")) {
    System.out.println("My current IP address is " + s.next());
} catch (java.io.IOException e) {
    e.printStackTrace();
}

Perl

use strict;
use warnings;
use LWP::UserAgent;

my $ua = new LWP::UserAgent();
my $ip = $ua->get('https://api.ipify.org')->content;
print 'My public IP address is: '. $ip;

VB.NET

Dim client as New System.Net.WebClient
Dim ip as String = client.DownloadString("https://api.ipify.org")

NodeJS

var http = require('http');

http.get({'host': 'api.ipify.org', 'port': 80, 'path': '/'}, function(resp) {
  resp.on('data', function(ip) {
    console.log("My public IP address is: " + ip);
  });
});

Racket

(require net/url)

(define ip (port->string (get-pure-port (string->url "https://api.ipify.org"))))
(printf "My public IP address is: ~a" ip)

Scala

val addr = scala.io.Source.fromURL("https://api.ipify.org").mkString
println(s"My public IP address is: $addr")

Javascript

<script type="application/javascript">
  function getIP(json) {
    document.write("My public IP address is: ", json.ip);
  }
</script>

<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>

jQuery

<script type="application/javascript">
  $(function() {
    $.getJSON("https://api.ipify.org?format=jsonp&callback=?",
      function(json) {
        document.write("My public IP address is: ", json.ip);
      }
    );
  });
</script>

C#

using System;
using System.Net;

namespace Ipify.Examples {
    class Program {
        public static void Main (string[] args) {
            WebClient webClient = new WebClient();
            string publicIp = webClient.DownloadString("https://api.ipify.org");
            Console.WriteLine("My public IP Address is: {0}", publicIp);
        }
    }
}

PowerShell

$ip = Invoke-WebRequest -Uri https://api.ipify.org
"My public IP address is: $ip"

PureBasic

InitNetwork()
*Buffer = ReceiveHTTPMemory("https://api.ipify.org?format=json")
If *Buffer
  ParseJSON(0, PeekS(*Buffer, MemorySize(*Buffer), #PB_UTF8))
  FreeMemory(*Buffer)
  Debug GetJSONString(GetJSONMember(JSONValue(0), "ip"))
EndIf

LiveCode

put "My public IP address is" && url "https://api.ipify.org"

Objective-C

NSURL *url = [NSURL URLWithString:@"https://api.ipify.org/"];
NSString *ipAddress = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"My public IP address is: %@", ipAddress);

Arduino

if (client.connect("api.ipify.org", 80)) {
    Serial.println("connected");
    client.println("GET / HTTP/1.0");
    client.println("Host: api.ipify.org");
    client.println();
} else {
    Serial.println("connection failed");
}

Libraries

If you want to use ipify in your favorite programming language, but want to keep your code nice and tidy, feel free to use one of our libraries below! They'll make your life a little bit easier and more enjoyable =)

NOTE: Don't see a library for your favorite programming language? If you create one, I'll be happy to link to it below! Just shoot me an email with the details and I'll gladly link to it!