[dns-operations] CLI Tool for DoH

fujiwara at jprs.co.jp fujiwara at jprs.co.jp
Tue Sep 29 04:05:17 UTC 2020


> From: cjc+dns-oarc at pumpky.net
> Looking for a command line tool to do testing of DoH. Something like
> dig or drill with DoH support. I suspect there's a Python tool or
> the like out there somewhere, but my google-fu is failing.
> 
> Don't want to re-invent the wheel if I don't have to.

Python has good DNS and HTTPS library.
You can write DoH client easily and quickly.

For me, I like perl. For example,
(Many codes from manual pages)
-------------------------------------------------------------
#!/usr/bin/env perl
use strict;
use Net::DNS::Packet;
use MIME::Base64;
use LWP::Protocol::https;
use LWP::UserAgent;
#
my $server = 'https://cloudflare-dns.com/dns-query';
our @ARGV;
# Usage: DoHclient.pl QNAME QTYPE QCLASS
my $qname = shift @ARGV;
if (!defined($qname)) { $qname = '.'; }
my $qtype = shift @ARGV;
if (!defined($qtype)) { $qtype = 'A'; }
my $qclass = shift @ARGV;
if (!defined($qclass)) { $qclass = 'IN'; }
#
my $q = new Net::DNS::Packet($qname, $qtype, $qclass);
$q->header->rd(1);
my $base64 = encode_base64($q->data);
chomp $base64;
my $url = sprintf("%s?dns=%s", $server, $base64);
my $ua = LWP::UserAgent->new();
my $r = $ua->get($url);
if ($r->is_success) {
	my $packet = new Net::DNS::Packet(\($r->decoded_content));
	$packet->print;
} else {
	die $r->status_line;
}
-------------------------------------------------------------

--
Kazunori Fujiwara, JPRS <fujiwara at jprs.co.jp>



More information about the dns-operations mailing list