Swirl

Wikipedia over DNS

I had written some code to take wikipedia articles and summarise them. I wanted to offer this for use in various places, now the obvious way to offer it is just a web service (via REST, SOAP, etc), but that's boring and I had a cunning plan. Why not offer it over DNS - it is basically a huge associative array and DNS is designed for this stuff.

So I wrote a little nameserver which returns the results as TXT records. There are some obvious limitations for example responses are limited to around 430 bytes (it only does UDP). It has advantages too, it gets cached at your nameserver and it is also faster than HTTP (no need to setup a TCP session).

To use it:

$ host -t txt foo.wp.dg.cx
foo.wp.dg.cx descriptive text "Foo may refer to: Foo, bar, and baz:
metasyntactic variables, \"Fool\", as a nonstandard spelling to indicate a
nonstandard pronunciation, Foo Fighters, a post-grunge group formed by Dave
Grohl, Foo fighters, a World War II term for various UFOs or mysterio\" \"us
aerial phenomena seen in the skies over Europe and the Pacific theatre, Foo,
also a known surname or last name of a... http://a.vu/w:Foo"

Using it from Perl is fairly easy too:


use Net::DNS;
my $res = Net::DNS::Resolver->new;

sub wikipedia {
  my($name) = @_;
  my $q = $res->query("$name.wp.dg.cx", "TXT");
  if($q) {
    for my $rr($q->answer) {
      next unless $rr->type eq "TXT";
      return join "", $rr->char_str_list;
    }
  }
} 

print wikipedia($ARGV[0]);

Unicode should be supported, all DNS queries are expected to be in UTF-8 (who needs IDN?). For example: dig +short txt '新疆.wp.dg.cx' | perl -pe's/\\(\d{1,3})/chr $1/eg' (the perl is just there to unescape the escaping dig does).


I also offer this over HTTP now, I've written a greasemonkey script to use it. There's also an example of how to use it via JavaScript callbacks here - which is interesting as it means you can add it to any web page.. (There are two interfaces, raw JSON as used by greasemonkey (example) and JS (example)).