forgotmyip.com returns your public IP as plain text to command-line tools, so it's easy to use in a terminal or a script. Browsers get the web page; other clients get just the address.
Quick commands
| Command | Returns |
|---|---|
curl https://forgotmyip.com |
Your IP over whichever protocol your connection uses |
curl -4 https://forgotmyip.com |
Your IPv4 address |
curl -6 https://forgotmyip.com |
Your IPv6 address (fails if you have no IPv6) |
wget -qO- https://forgotmyip.com |
Same as curl, using wget |
curl https://forgotmyip.com/ip |
Plain text for any client, including browsers |
curl https://forgotmyip.com/json |
JSON with ip, version and country |
JSON output
$ curl https://forgotmyip.com/json
{"ip":"203.0.113.42","version":4,"country":"US"}
With jq you can pick out one field:
curl -s https://forgotmyip.com/json | jq -r .country
Windows
Windows 10 includes curl.exe, starting with build 17063 (Microsoft). In Command Prompt:
curl https://forgotmyip.com
In PowerShell, use Invoke-RestMethod — alias irm. It returns plain-text responses as a string and converts JSON into an object (Microsoft Learn):
irm https://forgotmyip.com
(irm https://forgotmyip.com/json).country
Watch out: in Windows PowerShell 5.1, curl and wget are aliases for Invoke-WebRequest (Microsoft Learn), which returns a response object rather than just the text. Type curl.exe to run the real curl.
Use your IP in a script
Bash
IP=$(curl -s https://forgotmyip.com)
echo "My public IP is $IP"
PowerShell
$ip = (irm https://forgotmyip.com).Trim()
Write-Output "My public IP is $ip"
Python
from urllib.request import urlopen
ip = urlopen("https://forgotmyip.com/ip").read().decode().strip()
print("My public IP is", ip)
JavaScript (browser, or Node.js 18+)
Node.js 18 made the global fetch API available by default (Node.js).
const { ip, version } = await fetch("https://forgotmyip.com/json").then(r => r.json());
console.log(`IPv${version}: ${ip}`);
The endpoints send Access-Control-Allow-Origin: *, so they can be called from any web page.
Common uses
- Checking that a VPN or proxy is active (the IP should change).
- Updating a dynamic DNS record or firewall allow-list when your IP changes.
- Logging which public IP a server or CI job is using.
Please be kind: for scheduled jobs, checking every few minutes is plenty.