

Query DNS via a RESTful HTTP interface - jf
http://dig.jsondns.org/IN/news.ycombinator.com/A

======
tlrobinson
Very cool. It even supports JSONP. Here's a tiny page I threw together to
lookup domains: <http://tlrobinson.net/misc/domaincheck.html>

~~~
yannis
Love the jq comment!:) +1

------
IsaacSchlueter
Please serve JSON with the application/json content-type, not text/html.

If you want to debug it more easily in a browser, you can install the JSONView
Firefox extension. It's quite handy: <https://addons.mozilla.org/en-
US/firefox/addon/10869>

~~~
qeorge
Unfortunately, IE chokes on application/json. So its actually safer to use
application/javascript, or even text/html instead.

This was still present in IE7, but they may have fixed it in IE8.

~~~
bkudria
Um, so? Why exactly would you be using IE to retrieve JSON? It's an API,
right?

~~~
qeorge
There's all kinds of client side uses for APIs. Facebook Connect logins for
instance, which can't be initiated server side.

Sending application/json to older versions of IE can cause it to pop up Save
As dialogs, even in AJAX requests.

They did the same thing with application/xml+xhtml.

------
cperciva
Of course, in order for this to work, your HTTP client starts by doing a DNS
lookup for dig.jsondns.org...

~~~
jf
Of course! I'm not looking to replace DNS, just make it easier to use.

------
erbuhqergwer
Hmmm, I think it might have problems with underscores in hostnames. Before you
say that underscores aren't valid, they very much are. They're used for DKIM
and SIP for example:

root@haven:~# host -t txt dkim1._domainkey.grepular.com
dkim1._domainkey.grepular.com TXT "k=rsa;
p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDwe0CGlJQq6Y0poniuhn80rsC1kKrcVg19STXqgM8wxe4HidRjr8KfSfCo0wcgqVq8saqsB0JCt2WOquRlUG5qRtrZag6G/wpYkRYCjYm8VsaJDxNZFpiauXeyz9HGKkHTo2QxLVIYFzkSo7ZtRQNnUB1N12/v5BscLk6X1DlmawIDAQAB"

root@haven:~# host -t srv _sip._tcp.grepular.com _sip._tcp.grepular.com SRV 10
0 5060 voip.grepular.com root@haven:~#

Not just underscores. You can shove almost anything in the hostname part of a
dns lookup...

~~~
jf
Fixed.

<http://dig.jsondns.org/IN/dkim1._domainkey.grepular.com/TXT>

<http://dig.jsondns.org/IN/_sip._tcp.grepular.com/SRV>

<http://dig.jsondns.org/IN/_jabber._tcp.gmail.com/SRV>

------
erbuhqergwer
I notice you're using Googles DNS servers to do the lookups. This means it
will "incorrectly" return NXDOMAINs for any spamhaus.org DNSBL lookup. For
example:

<http://dig.jsondns.org/IN/2.0.0.127.zen.spamhaus.org/A>

Yet doing the lookup using my own DNS server:

root@haven:~# host -t a 2.0.0.127.zen.spamhaus.org 2.0.0.127.zen.spamhaus.org
A 127.0.0.2 2.0.0.127.zen.spamhaus.org A 127.0.0.4 2.0.0.127.zen.spamhaus.org
A 127.0.0.10 root@haven:~#

~~~
jf
Interesting. Do you have any suggestions for a better DNS server to use?

~~~
erbuhqergwer
You'll probably end up with the same issues with any publicly accessible
recursive resolver. The only way to be sure you're getting "good" DNS
responses is to use your own.

~~~
jf
The DNS library I'm using supports doing recursive queries - that'll likely be
the next feature I'll add to dig.jsondns.

------
moe
Why?

~~~
jf
This is part of a domain name registration service that I'm writing with Jeff
Lindsay.

It's also part of a larger project to make it trivial to work with DNS from
"the web". Soon your web server will also be a DNS server.

~~~
bretthoerner
> Soon your web server will also be a DNS server.

Why?

~~~
jf
Setup, configuration, and maintenance of DNS servers isn't simple. They need
to run as root on a server with a static IP.

Hosted DNS solutions cost money, don't always support all record types, and
rarely have programmatic interfaces.

In short, it'll make my life easier. Hopefully yours too.

~~~
sorbits
I would _love_ a simple way to manage my DNS entries, like a version
controlled text file :)

I presently use a free service (<http://gratisdns.dk>) and also run bind9 for
one domain (the free service can act as my backup NS) — I looked at
<http://cr.yp.to/djbdns.html> in my quest for something simpler, but I wasn’t
swayed.

Your comment made me optimistic, but correct me if I am wrong, but
dig.jsondns.org is completely unrelated to any of this — what I would need is
<http://github.com/jpf/eventdns> and dig.jsondns.org is more of a test server
for EventDNS if I am not mistaken?

~~~
jf
So yeah, after I make some changes to eventdns, you'll be able to use that to
host DNS from a text file. The path to the files and format will be the same
as what dig.jsondns.org returns.

------
timdorr
Only problem I see is that the results are cached. If you're trying to build a
live lookup tool, then that sort of kills it. I would love an API for DNS that
is non-cached so I can build tools for my support techs.

~~~
tlrobinson
HTTP caching maps nicely to DNS TTLs...

~~~
jf
Yes they do: <http://github.com/jpf/jsondns/blob/master/jsondns.rb#L66>

HTTP Status Codes also map pretty nicely to DNS RCODEs.

------
erbuhqergwer
It doesn't appear to handle SRV records either. These are used for various
things eg the extremely widely used SIP protocol.

~~~
jf
Really? It should support SRV records. Can you give me an example to help me
track down the bug?

~~~
erbuhqergwer
My mistake. I was looking up the SRV record for _sip._tcp.grepular.com and
assumed that the reason it failed was because it didn't support SRV. The
failure was the underscores though, which you've now fixed.

------
erbuhqergwer
You should be able to send multiple dns queries in a single http request.

