My IP API

If you need to find out your or your visitor's public IP address in a programmatical way then we have the right tool for you. Our free, simple, and easy to use RESTful API provides the caller's IP address in formats like TXT, CSV, JSON, JSONP, XML and YAML. Most formats also provide the proxy server's IP address if the service is accessed through a transparent proxy. If we can't detect a proxy then the proxy server's IP address is the same as the public IP address.
If you are just asking "What's my IP address" or if you want extended information about your public IP address please visit our My IP page.

API URL

The API URL has the following form:

http://api.ipaddress.com/myip?parameters

The list of supported parameters and returned values is enumerated further below. Parameters are submitted using a standard query string, and individual parameters are separated using the ampersand ( & ) character as shown in the following example:

http://api.ipaddress.com/myip?format=json&callback=myCallback

API Parameters

The My IP API supports the parameters listed below. All values are case sensitive unless noted otherwise. Some parameters are used for certain output formats only.
If you send a request with unsupported parameter values it might get answered with either 400 Bad Request or 404 Not Found HTTP status code.

ParameterRequiredPossible ValuesDefault ValueSupported Formats
formatno
  • csv - Comma Separated Values
  • json - JavaScript Object Notation
  • jsonp - JSON with Padding
  • txt - Plain Text
  • xml - Extensible Markus Language
  • yaml - YAML
txtn/a
callbacknoUp to 63 alphanumeric characters ([a-zA-Z0-9])callbackjsonp

API Return Values

A query to the API returns the caller's IP address and a possible proxy server IP address.

ValueDescriptionSupported Formats
ipaddressThe caller's IP addressAll
proxyThe IP address of the proxy server if one was detected, caller's IP address otherwiseAll but txt

API Usage Samples

Depending on your needs our API can provide the public IP address in various data formats. The most simple is the text format, and it only returns a single line consisting of the caller's public IP address. Other formats also provide the IP address of a proxy server if one is used. Please have a look at the samples further below to find out how the values are returned in individual formats.

Plain Text

CSV

http://api.ipaddress.com/myip?format=csv
ipaddress,proxy 54.158.212.93,54.158.212.93

JSON

http://api.ipaddress.com/myip?format=json
{"ipaddress":"54.158.212.93","proxy":"54.158.212.93"}

JSONP

http://api.ipaddress.com/myip?format=jsonp
callback({"ipaddress":"54.158.212.93","proxy":"54.158.212.93"});

JSONP with Custom Callback Function

http://api.ipaddress.com/myip?format=jsonp&callback=customCallback
customCallback({"ipaddress":"54.158.212.93","proxy":"54.158.212.93"});

XML

http://api.ipaddress.com/myip?format=xml
<?xml version="1.0"?><myip><ipaddress>54.158.212.93</ipaddress><proxy>54.158.212.93</proxy></myip>

YAML

http://api.ipaddress.com/myip?format=yaml
--- ipaddress: 54.158.212.93 proxy: 54.158.212.93

Sample Code

The API can be queried from almost any programming language, and even for a single programming language different methods may be available. The following code samples provide an overview about common techniques to retrieve the public IP address. To keep the examples simple error checking has been omitted.

PHP

<?php
$csv = array_map ('str_getcsv', file('http://api.ipaddress.com/myip?format=csv'));
echo "Public IP address: {$csv[1][0]}\n";
echo "Proxy IP address: {$csv[1][1]}\n";
?>
<?php
$xml = simplexml_load_file ('http://api.ipaddress.com/myip?format=xml');
echo "Public IP address: {$xml->ipaddress}\n";
echo "Proxy IP address: {$xml->proxy}\n";
?>
<?php
$ch = curl_init ('http://api.ipaddress.com/myip?format=json');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);
curl_close ($ch);
$json = json_decode ($data);
echo "Public IP address: {$json->ipaddress}\n";
echo "Proxy IP address: {$json->proxy}\n";
?>

Javascript

<script type="text/javascript">
function myip(callback){
  var r;
  if (window.XMLHttpRequest)r=new XMLHttpRequest();
  else r=new ActiveXObject("Microsoft.XMLHTTP");
  r.onreadystatechange=function(){
    if (r.readyState==4&&r.status=="200")callback(r.responseText);
  };
  r.open("GET","http://api.ipaddress.com/myip?format=json",true);
  r.send(null);
}
myip(function(response){
  var json=JSON.parse(response);
  document.write("<p>Public IP address: "+json.ipaddress+"</p>");
  document.write("<p>Proxy IP address: "+json.proxy+"</p>");
});
</script>

jQuery

<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $.getJSON("http://api.ipaddress.com/myip?format=json",function(json){
    document.write("<p>Public IP address: "+json.ipaddress+"</p>");
    document.write("<p>Proxy IP address: "+json.proxy+"</p>");
  });
});
</script>

Bash

#!/bin/bash
IP=$(curl -s http://api.ipaddress.com/myip)
echo "Public IP address: $IP"
#!/bin/bash
IP=`curl -s http://api.ipaddress.com/myip`
echo "Public IP address: $IP"
Back To Top