ipaddress.sh

Simple service to get the public IP address

        terminal ~ $ 
      

What's my IP address

Your IP Address:

Loading...

Usage Examples

Learn how to use our IP address service in different programming languages and tools:

Getting IP address using Python:


            import requests
            response = requests.get('https://ipaddress.sh')
            ip_address = response.text
            print("Your IP address is:", ip_address)
        

Getting IP address using Javascript:


            fetch('https://ipaddress.sh')
            .then(response => response.text())
            .then(ipAddress => {
            console.log("Your IP address is:", ipAddress);
            });
          

Getting IP address using Node.js (using node-fetch library):


            const fetch = require('node-fetch');
            fetch('https://ipaddress.sh')
            .then(response => response.text())
            .then(ipAddress => {
            console.log("Your IP address is:", ipAddress);
            });
          

Getting IP address using Ruby:


          require 'net/http'
          response = Net::HTTP.get(URI('https://ipaddress.sh'))
          puts "Your IP address is: #{response}"            
          

Getting IP address using PHP:


          <?php
          $ip_address = file_get_contents('https://ipaddress.sh');
          echo "Your IP address is: " . $ip_address;
          ?>
          

Getting IP address using CURL:

curl https://ipaddress.sh
          

Getting IP address using wget:

wget -qO- https://ipaddress.sh
          

Getting IP address using Java (using the java.net package):


            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();
                    }
                }
            }            
          

Getting IP address using C# (using System.Net.Http):


            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);
                    }
                }
            }
            
          

Getting IP address using Swift (using URLSession):


            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()
            
          

Getting IP address using Kotlin (using kotlinx.coroutines and ktor):


            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")
                }
            }            
          

Getting IP address using Rust (using reqwest crate):


            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),
                }
            }            
          

Getting IP address using Go (Golang):


            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