-
Notifications
You must be signed in to change notification settings - Fork 6
/
doh.pl
executable file
·43 lines (35 loc) · 881 Bytes
/
doh.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -s
use warnings;
use strict;
use LWP::UserAgent;
use MIME::Base64 qw(encode_base64url);
use Net::DNS;
our $k; # like curl --insecure
my %lwp;
%lwp = (ssl_opts => {
verify_hostname => 0,
SSL_verify_mode => 0,
}) if $k;
my $server = shift;
my $q = Net::DNS::Packet->new(@ARGV)->verbose;
$q->header->rd(1);
my $dns = encode_base64url $q->data;
my $ua = LWP::UserAgent->new(%lwp);
my $hr = $ua->get($server.'?dns='.$dns);
printf "%s%s\n%s\n", $hr->request->as_string,
$hr->status_line, $hr->headers_as_string;
if ($hr->is_success) {
Net::DNS::Packet->new($hr->content_ref)->verbose;
} else {
die $hr->content;
}
package Net::DNS::Packet;
use Data::Hexdumper qw(hexdump);
sub verbose {
my $p = shift;
my $len = length $p->data;
printf " 0x%04x = %d\n%s\n", $len, $len,
hexdump $p->data, { suppress_warnings => 1 };
$p->print;
return $p;
}