Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CentralNic
perl-doh
Commits
e1d81d67
Unverified
Commit
e1d81d67
authored
Jun 29, 2018
by
Gavin Brown
Browse files
support --help, use constants for templates, fall back to synthesised URL if none provided
parent
ec62585e
Changes
1
Hide whitespace changes
Inline
Side-by-side
hdig
View file @
e1d81d67
...
...
@@ -8,11 +8,12 @@ use Mozilla::CA;
use
Net::DNS::
Parameters
;
use
Net::
DNS
;
use
URI
;
use
Pod::
Usage
;
use
constant
URL_TEMPLATE
=>
'
https://%s/dns-query
';
use
constant
CONTENT_TYPE
=>
'
application/dns-message
';
use
strict
;
my
$ct
=
'
application/dns-message
';
my
(
$qname
,
$qtype
,
$qclass
,
$url
,
$debug
,
$insecure
);
my
(
$qname
,
$qtype
,
$qclass
,
$url
,
$debug
,
$insecure
,
$help
);
#
# dig-like command lines, things can appear in any order
...
...
@@ -24,7 +25,10 @@ my ($qname, $qtype, $qclass, $url, $debug, $insecure);
while
(
scalar
(
@ARGV
)
>
0
)
{
my
$param
=
shift
(
@ARGV
);
if
(
$param
=~
/^(-d|--debug)$/
)
{
if
(
$param
=~
/^(-h|--help)$/
)
{
$help
=
1
;
}
elsif
(
$param
=~
/^(-d|--debug)$/
)
{
$debug
=
1
;
}
elsif
(
$param
=~
/^(-k|--insecure)$/
)
{
...
...
@@ -37,7 +41,7 @@ while (scalar(@ARGV) > 0) {
}
else
{
if
('
@
'
eq
$
1
)
{
$url
=
sprintf
(
'
https://%s/dns-query
'
,
$
2
);
$url
=
sprintf
(
URL_TEMPLATE
,
$
2
);
}
else
{
$url
=
$param
;
...
...
@@ -75,24 +79,20 @@ while (scalar(@ARGV) > 0) {
}
}
$qtype
=
$qtype
||
'
A
';
$qclass
=
$qclass
||
'
IN
';
pod2usage
(
1
)
if
(
$help
);
if
(
!
$qname
)
{
print
STDERR
"
Error: no query name provided
\n
";
exit
(
1
);
}
elsif
(
!
$url
)
{
print
STDERR
"
Error: no URL provided
\n
";
exit
(
1
);
}
$url
=
sprintf
(
URL_TEMPLATE
,
(
Net::DNS::
Resolver
->
new
->
nameservers
)[
0
])
if
(
!
$url
);
$qname
=~
s/\.$//g
;
my
$packet
=
Net::DNS::
Packet
->
new
(
$qname
.
'
.
',
$qtype
,
$qclass
);
my
$packet
=
Net::DNS::
Packet
->
new
(
$qname
.
'
.
',
$qtype
||
'
A
'
,
$qclass
||
'
IN
'
);
my
$request
=
POST
(
$url
,
'
Content-Type
'
=>
$ct
,
'
Content
'
=>
$packet
->
data
);
$request
->
header
('
Accept
'
=>
$ct
);
my
$request
=
POST
(
$url
,
'
Content-Type
'
=>
CONTENT_TYPE
,
'
Content
'
=>
$packet
->
data
);
$request
->
header
('
Accept
'
=>
CONTENT_TYPE
);
print
STDERR
$request
->
as_string
if
(
$debug
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment