knadh / dns.toys

A DNS server that offers useful utilities and services over the DNS protocol. Weather, world time, unit conversion etc.
https://www.dns.toys
MIT License
2.49k stars 136 forks source link

Explicit IPv4 support #36

Closed guptayash closed 1 year ago

guptayash commented 2 years ago

Currently, in the case of dual-stack (where v4 and v6 are assigned) dig ip @dns.toys always returns a v6 address. It would be great to have the IP query return the v4 address when mentioned.

I am willing to work on this.

knadh commented 2 years ago

I'm not sure how the net lib behaves with dual stack IPs, but guessing killing the switch{} and splitting the cases to two if conditions should work. I've no way of testing this. Please feel free to send a PR if you're able to test this.

https://github.com/knadh/dns.toys/blob/master/cmd/dnstoys/handlers.go#L110

guptayash commented 1 year ago

Hey @knadh, sorry for delay in response. I figured that my DNS server is returning AAAA record for dns.toys and hence my request to dns.toys is always going via IPv6. Hence, there is no way for us to return IPv4 if the request is made over IPv6. Would love to hear your thoughts and close this issue.

knadh commented 1 year ago

I figured that my DNS server is returning AAAA record for dns.toys and hence my request to dns.toys is always going via IPv6. Hence, there is no way for us to return IPv4 if the request is made over IPv6.

Yep.

teutat3s commented 1 year ago

For the interested reader who lands here via search:

# IPv4
dig -4 ip @dns.toys

# IPv6
dig -6 ip @dns.toys