ogham / dog

A command-line DNS client.
https://dns.lookup.dog/
European Union Public License 1.2
6.06k stars 169 forks source link

better IP/PTR support #32

Open geeseven opened 3 years ago

geeseven commented 3 years ago

Greetings,

Currently, IP/PTR look ups do not have the same polish of other records. The help output states -q, --query=HOST Host name or IP address to query, but it does not work for IPv4 or IPv6.

$ dog --version 
dog ● command-line DNS client
v0.1.0
https://dns.lookup.dog/

$ dog --query=127.0.0.1
Status: NXDomain
SOA  35m04s A "a.root-servers.net." "nstld.verisign-grs.com." 2020111401 30m00s 15m00s 7d0h00m00s 1d0h00m00s

$ dig +short -x 127.0.0.1
localhost.localdomain.
localhost.

$ dog --query=::1
Status: NXDomain
SOA  35m11s A "a.root-servers.net." "nstld.verisign-grs.com." 2020111401 30m00s 15m00s 7d0h00m00s 1d0h00m00s

$ dig +short -x ::1
localhost.localdomain.
localhost.

One should not have to convert IPs to the in-addr.arpa or ip6.arpa domains, especially for IPv6. Should the default record for IPs be PTR?

$ dog 1.0.0.127.in-addr.arpa
SOA 127.in-addr.arpa. 3h00m00s A "localhost." "nobody.invalid." 1 1h00m00s 20m00s 7d0h00m00s 3h00m00s

$ dog 1.0.0.127.in-addr.arpa PTR
PTR 1.0.0.127.in-addr.arpa. 1h00m00s   "localhost.localdomain."
PTR 1.0.0.127.in-addr.arpa. 3h00m00s   "localhost."

$ dog 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
SOA 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 3h00m00s A "localhost." "nobody.invalid." 1 1h00m00s 20m00s 7d0h00m00s 3h00m00s

$ dog 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa PTR
PTR 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 1h00m00s   "localhost.localdomain."
PTR 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 3h00m00s   "localhost."

Also, ANY does not return PTR records for in-addr.arpa or ip6.arpa domains.

$ dog 1.0.0.127.in-addr.arpa ANY
SOA 127.in-addr.arpa. 3h00m00s A "localhost." "nobody.invalid." 1 1h00m00s 20m00s 7d0h00m00s 3h00m00s

$ dog 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ANY
SOA 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa. 3h00m00s A "localhost." "nobody.invalid." 1 1h00m00s 20m00s 7d0h00m00s 3h00m00s

This seems to be the only rough edge on an otherwise slick project.

ogham commented 3 years ago

Hi,

This is something I actually deliberately avoided implementing, but I've had a ton of requests for it!

My rationale for not including it is that we already have other tools to do this: host or nslookup. I gave some explanation over on Hacker News, saying that it's like if curl had a special flag to run curl ifconfig.me because that's one of the things you can use HTTP for. People responded saying they use dig for reverse lookups all the time, though.

It's not too hard a feature to add (mangle the input IP into a domain before sending it, and send PTR records specifically), so I'll probably end up doing it at some point anyway.

Also, ANY does not return PTR records for in-addr.arpa or ip6.arpa domains.

ANY returns whatever the nameserver wants it to return. Using the router my ISP gave me (not exactly the pinnacle of advanced technology), I get PTR results for both of those:

Screenshot 2020-11-15 at 14 20 08

geeseven commented 3 years ago

Hey @ogham,

Thanks for the timely reply. I had a feeling that this might have been a deliberate decision. I too use dig -x a fair amount and would prefer to use a single tool for all DNS queries.

I'll probably end up doing it at some point anyway.

Glad to hear that you flexible. In the mean time, I would recommend updating the help output as it is currently misleading.

ANY returns whatever the nameserver wants it to return.

TIL, thanks for sharing.

Sidenote, FreeBSD is already packaging dog.

$ pkg info dog
dog-0.1.0
Name           : dog
Version        : 0.1.0
Installed on   : Sun Nov 15 13:13:11 2020 CST
Origin         : dns/dog
Architecture   : FreeBSD:12:amd64
Prefix         : /usr/local
Categories     : net dns
Licenses       : EUPL
Maintainer     : vulcan@wired.sh
WWW            : https://dns.lookup.dog/
Comment        : Command-line DNS client
Options        :
    COMPLETIONS    : on
    DOCS           : on
Annotations    :
    FreeBSD_version: 1201000
    repo_type      : binary
    repository     : FreeBSD-faster
Flat size      : 677KiB
Description    :
Command-line DNS client, like dig.

It has colourful output, understands normal command-line argument syntax,
supports the DNS-over-TLS and DNS-over-HTTPS protocols, and can emit JSON.

WWW: https://dns.lookup.dog/
ogham commented 3 years ago

I'll add the FreeBSD link to the list, thanks!

What's wrong with the help output? Ah, is it the "Host name or IP address to query"? I may have got ahead of myself there.

geeseven commented 3 years ago

Ah, is it the "Host name or IP address to query"?

Yea, IP addresses currently do not work. See my pull request, #34.

I may have got ahead of myself there.

:wink: hehe

djmattyg007 commented 3 years ago

Just wanted to voice my support for better reverse DNS lookups. It's one of my primary use cases for using dig.

radek-sprta commented 2 years ago

Is this something you'd be willing to accept PRs for?

mrqwer88 commented 2 years ago

https://github.com/mrqwer88/dog/commit/7acfc357b3b3b3e38e3de33cc830c8b9bb197e44 write prototype for it.

Should be more dig-like -

./target/release/dog -x -q 127.0.0.1 -q 1.1.1.1 -q 2a00:1450:400f:80a::200e
PTR 1.0.0.127.in-addr.arpa.                                                    3h00m00s   "localhost."
PTR 1.1.1.1.in-addr.arpa.                                                        22m26s   "one.one.one.one."
PTR e.0.0.2.0.0.0.0.0.0.0.0.0.0.0.0.a.0.8.0.f.0.0.4.0.5.4.1.0.0.a.2.ip6.arpa. 22h36m46s   "arn11s03-in-x0e.1e100.net."
ket000 commented 2 years ago

Having a reverse lookup support will be nice. This will make one single tool for windows as dig is not available for windows.

polarathene commented 2 years ago

This will make one single tool for windows as dig is not available for windows.

It doesn't look like this project is maintained anymore. You might be interested in a Go based alternative doggo, it's actively maintained and inspired from dog, also has rDNS lookup :+1:

ket000 commented 2 years ago

Thanks for pointing out the alternative solution.

alfonsrv commented 1 year ago

My rationale for not including it is that we already have other tools to do this

Why would I even use dog in the first place, if I wanted to use the well-established tools that come pre-packaged with every OS?

cowens commented 1 year ago

My quick and dirty solution was to write a shell wrapper for dog:

#!/bin/zsh

dog=/usr/local/bin/dog

if [[ "$1" == "-x" ]]; then
        IFS="."
        echo $2 | read a b c d
        unset IFS

        $dog $d.$c.$b.$a.in-addr.arpa PTR
else
        $dog "$@"
fi
ImNtReal commented 10 months ago

If you're stuck on Windows, you can use something like this:

Import-Module IPv4Toolbox

if ($args[0] -like '-x') {
  dog.exe (ConvertTo-InverseAddress $args[1]) PTR
} else {
  dog.exe $args
}