What's my IP on the cli

I’ve so often googled “whats my ip” and today I was curious how to do the same on the cli. Seems that there are some DNS servers which return your IP address if you ask them nicely. The end result is this script, which I now have as ~/bin/whatsmyip:

#!/bin/bash
# From
# https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/
set -e

echo "IPv4: $(dig +short txt ch whoami.cloudflare @1.0.0.1)"
echo "IPv6: $(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com)"