SDKs overview
Icanhazip provides a minimalist HTTP API for retrieving a client's public IP address. Due to its straightforward nature—a simple GET request returning raw text—dedicated official Software Development Kits (SDKs) are not typically required in the same way they are for more complex APIs. Instead, developers often interact with Icanhazip using standard HTTP client libraries available in their preferred programming language. These libraries simplify the process of making web requests and parsing the response, which, in Icanhazip's case, is just the IP address as plain text. This approach aligns with the service's design philosophy of simplicity and directness, making it accessible from virtually any environment capable of making an HTTP request. For more complex API interactions, an SDK might handle authentication, error parsing, and data serialization, as seen with services like Stripe's payment processing API documentation.
While Icanhazip itself does not offer a suite of complex API endpoints, the concept of an SDK or library in this context refers to language-specific wrappers or convenience functions that abstract the HTTP call to icanhazip.com. These can be official, maintained by the Icanhazip project, or community-contributed, offering varying levels of functionality and maintenance. The primary benefit of using such a library, even for a simple service, is to encapsulate the URL, handle potential network errors, and provide a clean, idiomatic interface for fetching the IP address within a given programming language.
Official SDKs by language
Icanhazip's core functionality is accessible via a direct HTTP GET request to https://icanhazip.com. Given this simplicity, Icanhazip does not maintain a comprehensive set of official, language-specific SDKs in the traditional sense, as the primary interaction is a basic web request. Instead, the service is designed for direct consumption using standard HTTP client libraries inherent to most programming languages. This design choice minimizes dependencies and maximizes compatibility across different development environments. The table below outlines how developers typically interact with Icanhazip, treating common HTTP clients as de facto "SDKs" for this service.
| Language | Common HTTP Client / "Package" | Install Command (Example) | Maturity |
|---|---|---|---|
| Python | requests |
pip install requests |
Stable (external library) |
| Node.js | node-fetch (or built-in http/https) |
npm install node-fetch |
Stable (external library) |
| Ruby | net/http (built-in) |
(No install needed) | Stable (built-in) |
| PHP | GuzzleHttp/guzzle |
composer require guzzlehttp/guzzle |
Stable (external library) |
| Go | net/http (built-in) |
(No install needed) | Stable (built-in) |
| Java | java.net.http (built-in since Java 11) |
(No install needed) | Stable (built-in) |
These clients are widely adopted within their respective ecosystems for general HTTP communication, including interacting with services like Icanhazip. Their maturity and stability are high, given their broad use cases beyond just IP address lookup. More details on Icanhazip's usage can be found on its official website.
Installation
Installation for Icanhazip "SDKs" primarily involves installing standard HTTP client libraries for your chosen programming language. Since Icanhazip doesn't distribute dedicated SDK packages through language-specific repositories (like PyPI for Python or npm for Node.js), you'll typically install a general-purpose HTTP library.
Python
For Python, the requests library is a common choice for making HTTP requests:
pip install requests
Node.js
In Node.js, you might use node-fetch for a browser-like fetch API, or the built-in http/https modules:
npm install node-fetch
Ruby
Ruby's standard library includes net/http, requiring no external installation:
require 'net/http'
require 'uri'
PHP
Guzzle is a popular HTTP client for PHP, installed via Composer:
composer require guzzlehttp/guzzle
Go
Go's standard library net/http module is used for HTTP requests and requires no separate installation:
import (
"fmt"
"io"
"net/http"
)
Java
Java's built-in java.net.http client (available since Java 11) or older HttpURLConnection are used, requiring no external dependencies:
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
// ...
Quickstart example
The following examples demonstrate how to retrieve your public IP address using Icanhazip with common HTTP client libraries in various programming languages. These snippets illustrate the basic process of making a GET request and reading the plain text response.
Python Quickstart
import requests
try:
response = requests.get('https://icanhazip.com')
response.raise_for_status() # Raise an exception for HTTP errors
ip_address = response.text.strip()
print(f"Your public IP address is: {ip_address}")
except requests.exceptions.RequestException as e:
print(f"Error fetching IP address: {e}")
Node.js Quickstart
import fetch from 'node-fetch';
async function getPublicIp() {
try {
const response = await fetch('https://icanhazip.com');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const ipAddress = (await response.text()).trim();
console.log(`Your public IP address is: ${ipAddress}`);
} catch (error) {
console.error(`Error fetching IP address: ${error}`);
}
}
getPublicIp();
Ruby Quickstart
require 'net/http'
require 'uri'
def get_public_ip
uri = URI.parse('https://icanhazip.com')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
begin
response = http.request(request)
if response.code == '200'
puts "Your public IP address is: #{response.body.strip}"
else
puts "Error fetching IP address: HTTP #{response.code}"
end
rescue StandardError => e
puts "Error fetching IP address: #{e.message}"
end
end
get_public_ip
PHP Quickstart
<?php
require 'vendor/autoload.php'; // For Guzzle
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
function getPublicIp(): void
{
$client = new Client();
try {
$response = $client->request('GET', 'https://icanhazip.com');
if ($response->getStatusCode() === 200) {
$ipAddress = trim($response->getBody()->getContents());
echo "Your public IP address is: {$ipAddress}\n";
} else {
echo "Error fetching IP address: HTTP " . $response->getStatusCode() . "\n";
}
} catch (RequestException $e) {
echo "Error fetching IP address: " . $e->getMessage() . "\n";
}
}
getPublicIp();
?>
Go Quickstart
package main
import (
"fmt"
"io"
"net/http"
)
func main() {
resp, err := http.Get("https://icanhazip.com")
if err != nil {
fmt.Printf("Error fetching IP address: %v\n", err)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
fmt.Printf("Error: Received non-200 HTTP status: %d\n", resp.StatusCode)
return
}
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response body: %v\n", err)
return
}
ipAddress := string(body)
fmt.Printf("Your public IP address is: %s\n", ipAddress)
}
Java Quickstart
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class IcanhazipQuickstart {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://icanhazip.com"))
.build();
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
String ipAddress = response.body().trim();
System.out.println("Your public IP address is: " + ipAddress);
} else {
System.err.println("Error fetching IP address: HTTP " + response.statusCode());
}
} catch (IOException | InterruptedException e) {
System.err.println("Error fetching IP address: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore interrupt status
}
}
}
Community libraries
Given the simplicity of Icanhazip's API, which primarily involves a single HTTP GET request to icanhazip.com, the landscape of community-contributed libraries is less about complex SDKs and more about utility wrappers or command-line tools built on top of the service. These community projects often aim to provide even simpler interfaces for specific use cases or integrate Icanhazip's functionality into existing workflows or frameworks.
For instance, developers might create shell scripts that leverage curl or wget to interact with icanhazip.com, then integrate these scripts into larger automation tasks. Similarly, small Python or Node.js modules exist that wrap the HTTP request in a single function call, abstracting away the boilerplate. These are typically found on platforms like GitHub or package repositories, often as lightweight utilities rather than full-fledged SDKs. Searching for "icanhazip" on Python Package Index (PyPI) or npm registry can reveal various community contributions that simplify the interaction, though many developers opt for direct HTTP client usage due to the API's minimal complexity. The common approach for such simple services is to use the language's native HTTP capabilities or well-established third-party HTTP clients, as outlined in the official SDKs table.
Community efforts may also include plugins for network monitoring tools, integrations into cloud infrastructure scripts (e.g., for dynamically updating firewall rules based on an egress IP), or components within larger open-source projects. However, direct official endorsement or maintenance of these by Icanhazip is generally not provided. Users should evaluate community libraries based on their specific needs, maintenance status, and security practices. The official Icanhazip website remains the authoritative source for understanding the core service functionality and direct usage guidelines.