The dig command is deprecated. I'm using drill from ldns. Drill doesn't seem to have a short option to show only the ip. Does anyone know how I can make it show only the ip and not the other text.
3 Answers
Found a way to do it with curl and cloudflare
curl -fSs https://1.1.1.1/cdn-cgi/trace | awk -F= '/ip/ { print $2 }'
dig
with+short
look like this:
$ dig +short example.com
XXX.XX.XX.XXX
So, you could simply do:
$ drill example.com | awk '{if(NF > 0 && substr($1,1,1) != ";") print $NF }'
XXX.XX.XX.XXX
Understanding my awk
if (NF > 0) # If the line is not empty
if (substr($1,1,1) != ";") # If the first character is not `;`
print $NF # Print the last column.
A little late the party here, but it looks like drill
~now~ has a -Q
("quiet") flag that does the same as dig's +short
:
$ drill -Q superuser.com
104.18.8.56
104.18.9.56
UPDATE: Looks like the feature has been in ldns
since at least the 1.0.0 release. You probably just missed it in your research because drill
doesn't aim to be a 100% drop-in replacement for dig
?
Previous Answer
What's a little surprising is, that feature was apparently committed in 2005, but not in a released version until Nov 2021.
I'm not sure what caused it (and other commits) to sit in limbo for 16 years, but at least you have a
drill
-native solution now!
dig
is deprecated? I missed that news. Is it a joke?dig
with thebind-tools
package (archlinux.org/packages/extra/x86_64/bind-tools) right ?