$ curl 'https://api.ipify.org?format=json'
{"ip":"185.103.110.182"}
$ curl 'https://api64.ipify.org?format=json'
{"ip":"2a00:1450:400f:80d::200e"}
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 can use it without limit (even if you're doing millions of requests per minute.
It works flawlessly with both IPv4 and IPv6 addresses, so no matter what sort of technology you're using, there won't be issues.
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!
ipify is completely open source (check out the GitHub repository).
No visitor information is ever logged. Period.
Lastly, ipify is open source so there's no need to worry about the domain name disappearing in three years or anything like that: ipify is here to stay!
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 URL | Response Type | Sample Output (IPv4) |
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"}); |
API URL | Response Type | Sample Output (IPv4/IPv6) |
https://api64.ipify.org |
text |
98.207.254.136 or 2a00:1450:400f:80d::200e |
https://api64.ipify.org?format=json |
json |
{"ip":"98.207.254.136"} or {"ip":"2a00:1450:400f:80d::200e"} |
https://api64.ipify.org?format=jsonp |
jsonp |
callback({"ip":"98.207.254.136"}); or callback({"ip":"2a00:1450:400f:80d::200e"}); |
https://api64.ipify.org?format=jsonp&callback;=getip |
jsonp |
getip({"ip":"98.207.254.136"}); or getip({"ip":"2a00:1450:400f:80d::200e"}); |
This section contains some common usage patterns from a variety of programming languages. Want something included that isn't listed here? Email us!
#!/bin/bash
ip=$(curl -s https://api.ipify.org)
echo "My public IP address is: $ip"
ip=`curl -s https://api.ipify.org`
echo("My public IP address is: $ip")
# 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: {}'.format(ip))
require "net/http"
ip = Net::HTTP.get(URI("https://api.ipify.org"))
puts "My public IP Address is: " + ip
<?php
$ip = file_get_contents('https://api.ipify.org');
echo "My public IP address is: " . $ip;
?>
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();
}
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;
var httpClient = new HttpClient();
var ip = await httpClient.GetStringAsync("https://api.ipify.org");
Console.WriteLine($"My public IP address is: {ip}");
Dim httpClient As New System.Net.Http.HttpClient
Dim ip As String = Await httpClient.GetStringAsync("https://api.ipify.org")
Console.WriteLine($"My public IP address is: {ip}")
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);
});
});
package main
import (
"io/ioutil"
"net/http"
"os"
)
func main() {
res, _ := http.Get("https://api.ipify.org")
ip, _ := ioutil.ReadAll(res.Body)
os.Stdout.Write(ip)
}
(require net/url)
(define ip (port->string (get-pure-port (string->url "https://api.ipify.org"))))
(printf "My public IP address is: ~a" ip)
;This example requires the drakma http package installed.
;It can be found here: http://www.weitz.de/drakma
(let ((stream
(drakma:http-request "https://api.ipify.org" :want-stream t)))
(let ((public-ip (read-line stream)))
(format t "My public IP address is: ~A" public-ip)))
Dim s As New HTTPSecureSocket
Dim t As String = s.Get("https://api.ipify.org",10)
MsgBox "My public IP Address is: " + t
val addr = scala.io.Source.fromURL("https://api.ipify.org").mkString
println(s"My public IP address is: $addr")
<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>
<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>
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);
}
}
}
:inets.start
{:ok, {_, _, inet_addr}} = :httpc.request('http://api.ipify.org')
:inets.stop
import HttpClient
var ip = newHttpClient().getContent("https://api.ipify.org")
echo("My public IP address is: ", ip)
$ip = Invoke-RestMethod -Uri 'https://api.ipify.org?format=json'
"My public IP address is: $($ip.ip)"
socket_http = require "http.compat.socket"
body = assert(socket_http.request("https://api.ipify.org"))
print(body)
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
put "My public IP address is" && url "https://api.ipify.org"
NSURL *url = [NSURL URLWithString:@"https://api.ipify.org/"];
NSString *ipAddress = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"My public IP address is: %@", ipAddress);
import Foundation
let url = URL(string: "https://api.ipify.org")
do {
if let url = url {
let ipAddress = try String(contentsOf: url)
print("My public IP address is: " + ipAddress)
}
} catch let error {
print(error)
}
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");
}
$b = TimerInit()
$Read = InetRead("https://api.ipify.org",1)
$sData = BinaryToString($Read)
MsgBox(64,"Information","Your IP Address: " & $sData & @CRLF & "Elapsed Time: " & StringLeft(TimerDiff($b) / 1000,4) & " seconds.")
filename ipresp "%sysfunc(pathname(work))\ipify-response.html";
proc http
url="https://api.ipify.org"
method=GET
out=ipresp
;
run;
data null;
length ip $ 20;
infile ipresp recfm=f lrecl=32000 encoding='utf-8' truncover;
input ip :$20.;
**Create a macro variable "IP" with the ip address: ;
call symput('IP',cats(ip));
**Print the ip address to the log: ;
put 'NOT' 'E: >>>>>>>>>>>> Official IP: ' ip ' <<<<<<<<<<<<<<<<<<';
run;
filename ipresp;
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 us an email with the details and I'll gladly link to it!