How to check your public IP with curl

Use an HTTPS endpoint to discover the address a public server sees.

A router, VPN, or proxy may translate your address before traffic reaches the internet. A public endpoint reports the source address visible at the destination.

Return only the address

curl https://tools.vishow.info/ip

Save it in a shell variable

public_ip="$(curl --fail --silent --show-error https://tools.vishow.info/ip)"
printf '%s\n' "$public_ip"

Why the address may change

Residential providers may assign dynamic addresses. Mobile networks can share addresses, and a VPN normally exposes its exit address.