Last active
September 25, 2020 10:39
-
-
Save jnerin/56ff79c5872855fa8957f6cccdbf1587 to your computer and use it in GitHub Desktop.
Get external IP from commandline by querying some DNS servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Faster with dig | |
dig -4 +short myip.opendns.com @resolver1.opendns.com # -4 needed to force ipv4 connectivity as resolver1.opendns.com doesn't return any result for this over ipv6 | |
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"' # IPv4 | |
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"' # IPv6 | |
# Slower with curl | |
curl -4 https://diagnostic.opendns.com/myip | |
curl -6 https://diagnostic.opendns.com/myip | |
curl -4 https://icanhazip.com | |
curl -6 https://icanhazip.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment