How to Get Your Public IP Address From the Command Line
The quickest way to get your public IP address from a terminal is curl https://ipcomet.com. It prints your address and nothing else, so the output can go straight into a script. This guide shows the same one-liner on macOS, Linux and Windows, how to do it from Python and Node.js, how to get your location and ISP as JSON, and how to choose between IPv4 and IPv6.
The one-line answer
curl https://ipcomet.comThe output is a single line such as 203.0.113.7. The home page recognises command-line clients (curl, wget, PowerShell and similar) by their User-Agent and returns just the address instead of the web page. In scripts, use the explicit endpoint https://ipcomet.com/api/ip, which always returns plain text.
macOS and Linux
curl https://ipcomet.com/api/ip
wget -qO- https://ipcomet.com/api/ipmacOS includes curl but not wget. To keep the result in a shell variable, use MYIP=$(curl -s https://ipcomet.com/api/ip). The -s flag hides curl's progress meter.
Windows
Windows 10 and 11 ship with curl, so curl.exe https://ipcomet.com/api/ip works in both Command Prompt and PowerShell. Type curl.exe rather than curl in PowerShell, where curl can be an alias for Invoke-WebRequest. The native PowerShell way is:
(Invoke-RestMethod https://ipcomet.com/api/ip).Trim()Python
With the requests library:
import requests
print(requests.get("https://ipcomet.com/api/ip", timeout=10).text.strip())With only the standard library, set a User-Agent. Python's default one (Python-urllib) is rejected by the bot protection in front of many sites, including this one, which answers with a 403 error (Cloudflare error 1010):
import urllib.request
req = urllib.request.Request("https://ipcomet.com/api/ip", headers={"User-Agent": "my-script/1.0"})
print(urllib.request.urlopen(req, timeout=10).read().decode().strip())JavaScript and Node.js
const ip = (await (await fetch("https://ipcomet.com/api/ip")).text()).trim();
console.log(ip);This works in Node.js 18 and later, which has fetch built in, and in a browser page, because the endpoint allows cross-origin requests.
Get your location and ISP as JSON
curl https://ipcomet.com/api/meThe response describes the connection that made the request. An example, with made-up values:
{
"ip": "203.0.113.7",
"version": 4,
"city": "Mumbai",
"region": "Maharashtra",
"country": "India",
"countryCode": "IN",
"timezone": "Asia/Kolkata",
"asn": 64500,
"org": "Example Broadband Ltd"
}The full response also has the postal code, latitude and longitude, and a few details about the connection (the edge location, the HTTP and TLS versions and the round-trip time). To pick out one field, pipe it through jq: curl -s https://ipcomet.com/api/me | jq -r .country.
To look up any other address, use curl "https://ipcomet.com/api/lookup?q=8.8.8.8". It returns the IP version, hostname, city, region, country, coordinates, timezone, ASN and network owner. Lookups are limited to 60 a minute per caller, and location data is approximate because it comes from network records, not GPS. The About page lists where each piece of data comes from.
Force IPv4 or IPv6
If your connection has both, add -4 or -6 to curl: curl -4 https://ipcomet.com forces IPv4, and curl -6 https://ipcomet.com forces IPv6, which only works if your connection has IPv6. The IPv4 vs IPv6 guide explains the difference.
Other services you will see recommended
curl ifconfig.me,curl icanhazip.com,curl api.ipify.organdcurl ipinfo.io/ipare other free services that return a bare address in the same way.- Without HTTP, you can ask a DNS resolver instead:
dig +short myip.opendns.com @resolver1.opendns.com.
They all report the address the internet sees, so they should agree.
Why do two services show different IP addresses?
If they differ, your router may be sharing traffic across two internet connections, or a VPN may be carrying only some of your traffic. The reputation tool shows what kind of network each address belongs to, and the WebRTC leak test helps when a VPN is involved.
These commands return your public address, the one websites see. For the private address on your own network, such as 192.168.1.20, see how to find your IP address and public vs private IP addresses.
Limits and privacy
No key or sign-up is needed. Please keep requests reasonable: checking every few minutes is fine, but calling it in a tight loop may be rate limited. ipcomet does not store or log the addresses it sees, as the privacy page explains. The free IP API page lists every endpoint with its exact rate limit. Try it in the browser first with the what is my IP address page.
Try it yourself
See the real numbers for your own connection with our free tools.