Simple service to get the public IP address
terminal ~ $
Loading...
Learn how to use our IP address service in different programming languages and tools:
import requests
response = requests.get('https://ipaddress.sh')
ip_address = response.text
print("Your IP address is:", ip_address)
fetch('https://ipaddress.sh')
.then(response => response.text())
.then(ipAddress => {
console.log("Your IP address is:", ipAddress);
});
const fetch = require('node-fetch');
fetch('https://ipaddress.sh')
.then(response => response.text())
.then(ipAddress => {
console.log("Your IP address is:", ipAddress);
});
require 'net/http'
response = Net::HTTP.get(URI('https://ipaddress.sh'))
puts "Your IP address is: #{response}"
<?php
$ip_address = file_get_contents('https://ipaddress.sh');
echo "Your IP address is: " . $ip_address;
?>
curl https://ipaddress.sh
wget -qO- https://ipaddress.sh
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class JavaExample {
public static void main(String[] args) {
try {
URL url = new URL("https://ipaddress.sh");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String ipAddress = reader.readLine();
reader.close();
System.out.println("Your IP address is: " + ipAddress);
} catch (Exception e) {
e.printStackTrace();
}
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
class CSharpExample {
static async Task Main() {
using (var client = new HttpClient()) {
HttpResponseMessage response = await client.GetAsync("https://ipaddress.sh");
response.EnsureSuccessStatusCode();
string ipAddress = await response.Content.ReadAsStringAsync();
Console.WriteLine("Your IP address is: " + ipAddress);
}
}
}
import Foundation
let url = URL(string: "https://ipaddress.sh")!
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
guard let data = data, error == nil else {
print("Error: \(error?.localizedDescription ?? "Unknown error")")
return
}
let ipAddress = String(data: data, encoding: .utf8)
print("Your IP address is: \(ipAddress ?? "No data")")
}
task.resume()
import io.ktor.client.*
import io.ktor.client.request.*
import kotlinx.coroutines.runBlocking
fun main() {
val client = HttpClient()
runBlocking {
val ipAddress = client.get("https://ipaddress.sh")
println("Your IP address is: $ipAddress")
}
}
use reqwest::Error;
async fn fetch_ip_address() -> Result {
let response = reqwest::get("https://ipaddress.sh").await?;
let ipAddress = response.text().await?;
Ok(ipAddress)
}
#[tokio::main]
async fn main() {
match fetch_ip_address().await {
Ok(ipAddress) => println!("Your IP address is: {}", ipAddress),
Err(error) => println!("Error: {}", error),
}
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
resp, err := http.Get("https://ipaddress.sh")
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
ipAddress, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Your IP address is:", string(ipAddress))
}
Now serving 2M-3M queries per day.
Find my IP address