My IP
Retrieve your public IPv4/IPv6 address via a simple web interface or API endpoint. Integrate instant client IP detection into scripts and applications for dynamic network setups.
IPv4:
IPv6:
Use one of the methods below in your application or command line.
The return will always be the IPv4 or IPv6 of the requester.
There are 3 hosts available that detect IP.
- ip.isp.tools – Detects IPv4 or IPv6. Responds with the IP used in the connection.
- ipv4.isp.tools – Forces resolution of IPv4 only.
- ipv6.isp.tools – Forces resolution of IPv6 only.
Linux Terminal
Choose one of the hosts and call it using the curl command.
Example:
curl ip.isp.tools
curl ipv4.isp.tools
curl ipv6.isp.tools
You can also force curl to connect to a version:
$ curl -4 ip.isp.tools
$ curl -6 ip.isp.tools
Or automate it by inserting it into ~/.bashrc:
$ printf '\n# ISP.Tools IP helpers
ip() { [ "$#" -eq 0 ] && curl -fsSL ip.isp.tools || command ip "$@"; }
ipv4() { [ "$#" -eq 0 ] && curl -fsSL ipv4.isp.tools || command ipv4 "$@"; }
ipv6() { [ "$#" -eq 0 ] && curl -fsSL ipv6.isp.tools || command ipv6 "$@"; }
export -f ip ipv4 ipv6\n' >> ~/.bashrc && source ~/.bashrc
And use it like this:
$ ip
179.104.127.31
$ ipv4
179.104.127.31
$ ipv6
2804:1e68:300f:d1af:f8d9:dfa1:3278:acb3
Javascript
// Javascript
const fetch = require('node-fetch');
const url = 'https://ip.isp.tools/json';
fetch(url)
.then(res => res.json())
.then(data => console.log(data.ip));
React
// React: fetch and hooks
import React, { useState, useEffect } from 'react';
function IPDisplay() {
const [ip, setIp] = useState('');
useEffect(() => {
fetch('https://ip.isp.tools/json')
.then(res => res.json())
.then(data => setIp(data.ip))
.catch(err => console.error(err));
}, []);
return (
Your IP:
{ip ? ip : "Loading..."}
);
}
export default IPDisplay;
// React: fetch with async/await
import React, { useState, useEffect } from 'react';
function IPFetcher() {
const [ip, setIp] = useState('');
useEffect(() => {
async function fetchIp() {
try {
const res = await fetch('https://ip.isp.tools/json');
const data = await res.json();
setIp(data.ip);
} catch (error) {
console.error(error);
}
}
fetchIp();
}, []);
return (
Your IP Address
{ip || 'Loading...'}
);
}
export default IPFetcher;
Alpine.JS
Your IP Address:
Vue.JS
Your IP Address:
{{ ip }}
Svelte
Your IP Address:
{ip}
Python
import requests
request = requests.get('https://ip.isp.tools/json').json()
ip = request['ip']
type_ip = request['type']
print(ip, type_ip)
PHP
Go
package main
import (
"encoding/json"
"fmt"
"net/http"
)
func main() {
resp, _ := http.Get("https://ip.isp.tools/json")
defer resp.Body.Close()
var d struct{ IP string }
json.NewDecoder(resp.Body).Decode(&d)
fmt.Println(d.IP)
}
Java
import java.net.http.*; import java.net.URI; import com.fasterxml.jackson.databind.*;
public class Main {
public static void main(String[] args)throws Exception {
String b = HttpClient.newHttpClient()
.send(HttpRequest.newBuilder(URI.create("https://ip.isp.tools/json")).build(),
HttpResponse.BodyHandlers.ofString())
.body();
System.out.println(new ObjectMapper()
.readTree(b).get("ip").asText());
}
}
C#
using System;
using System.Net.Http;
using System.Text.Json;
class Program {
static async System.Threading.Tasks.Task Main() {
var j = await new HttpClient()
.GetStringAsync("https://ip.isp.tools/json");
Console.WriteLine(
JsonDocument.Parse(j)
.RootElement.GetProperty("ip")
.GetString()
);
}
}
Ruby
require 'net/http'
require 'json'
data = JSON.parse(Net::HTTP.get(URI('https://ip.isp.tools/json')))
puts data['ip']
Bash Linux
#!/bin/bash
ip=$(curl -s https://ip.isp.tools/json | jq -r .ip)
echo $ip
Windows PowerShell
$ip = (Invoke-RestMethod -Uri 'https://ip.isp.tools/json').ip
Write-Host $ip
Windows BAT
@echo off
for /f "tokens=2 delims=:" %%a in ('curl -s https://ip.isp.tools/json ^| findstr "ip"') do set IP=%%a
set IP=%IP:"=%
echo %IP%
Zsh (macOS)
#!/bin/zsh
ip=$(curl -s https://ip.isp.tools/json | jq -r .ip)
echo $ip
Swift
#!/usr/bin/swift
import Foundation
let url = URL(string: "https://ip.isp.tools/json")!
let data = try! Data(contentsOf: url)
let obj = try! JSONSerialization.jsonObject(with: data) as! [String:Any]
print(obj["ip"] as! String)
Rust
use reqwest::blocking::get;
use serde_json::Value;
fn main() {
let resp = get("https://ip.isp.tools/json").unwrap().text().unwrap();
let ip = serde_json::from_str::(&resp).unwrap()["ip"].as_str().unwrap();
println!("{}", ip);
}
Dart
import 'dart:convert';
import 'dart:io';
void main() async {
var resp = await HttpClient()
.getUrl(Uri.parse('https://ip.isp.tools/json'))
.then((r) => r.close())
.then((r) => r.transform(utf8.decoder).join());
print(json.decode(resp)['ip']);
}