Print your public IP address from Linux, macOS, FreeBSD or Unix/Windows shell:
curl https://checkip.amazonaws.com

Try dig
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com

See https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/ for more.

@nixCraft what about using stunclient?

@climbertobby @nixCraft

Thanks. STUN seems to be designed to solve this Problem specifically.

stunclient stunserver.stunprotocol.org
stunclient --family 6 stunserver.stunprotocol.org

@climbertobby @nixCraft

If you want to use a random STUN-Server:

stunclient --family 4 $(curl -s https://raw.githubusercontent.com/pradt2/always-online-stun/master/valid_ipv4s.txt | shuf -n 1 | sed -n 's/^\[\?\(.*[0-9,a-f]\)\]\?:\([0-9]*\)$/\1 \2/p') | sed -n 's/^Mapped address: \(.*\)[\.|:][0-9]*$/\1/p'

stunclient --family 6 $(curl -s https://raw.githubusercontent.com/pradt2/always-online-stun/master/valid_ipv6s.txt | shuf -n 1 | sed -n 's/^\[\?\(.*[0-9,a-f]\)\]\?:\([0-9]*\)$/\1 \2/p') | sed -n 's/^Mapped address: \(.*\)[\.|:][0-9]*$/\1/p'