1 // brain dead command line tool to query DNS
6 #include <glog/logging.h>
8 void do_dotted_quad(char const* addr
)
12 std::string reversed
{IP4::reverse(addr
)};
14 constexpr const char* const rbls
[]
15 = {"zen.spamhaus.org", "b.barracudacentral.org"};
17 for (auto rbl
: rbls
) {
18 std::string lookup
= reversed
+ rbl
;
20 DNS::Domain
dom(lookup
.c_str());
21 DNS::Query
<DNS::RR_type::A
> q(res
, dom
);
23 if (q
.get_rcode() == DNS::Pkt_rcode::NOERROR
) {
24 DNS::Rrlist
<DNS::RR_type::A
> rrlst(q
);
27 std::cout
<< "found in " << rbl
<< '\n';
28 std::vector
<std::string
> codes
= rrlst
.get();
29 for (auto code
: codes
) {
30 std::cout
<< code
<< '\n';
35 if (q
.get_rcode() == DNS::Pkt_rcode::NXDOMAIN
) {
36 std::cout
<< "not found in " << rbl
<< '\n';
39 std::cout
<< "Error from lookup at " << rbl
<< " " << q
.get_rcode()
48 = DNS::get_records
<DNS::RR_type::PTR
>(res
, reversed
+ "in-addr.arpa");
50 for (auto ptr
: ptrs
) {
51 // chop off the trailing '.'
52 auto length
= ptr
.length();
53 if (length
&& ('.' == ptr
.at(length
- 1))) {
54 ptr
.erase(length
- 1, 1);
56 auto addrs
= DNS::get_records
<DNS::RR_type::A
>(res
, ptr
);
57 for (auto const& a
: addrs
) {
65 std::cout
<< "no fcrdns\n";
69 std::cout
<< fcrdns
<< '\n';
71 auto txts
= DNS::get_records
<DNS::RR_type::TXT
>(res
, fcrdns
);
72 for (auto const& txt
: txts
) {
73 std::cout
<< "\"" << txt
<< "\"\n";
77 void do_domain(char const* domain
)
81 auto addrs
= DNS::get_records
<DNS::RR_type::A
>(res
, domain
);
82 for (auto const& a
: addrs
) {
83 std::cout
<< a
<< '\n';
86 auto txts
= DNS::get_records
<DNS::RR_type::TXT
>(res
, domain
);
87 for (auto const& txt
: txts
) {
88 std::cout
<< "\"" << txt
<< "\"\n";
92 int main(int argc
, char const* argv
[])
94 google::InitGoogleLogging(argv
[0]);
96 for (int i
= 1; i
< argc
; ++i
) {
97 if (IP4::is_address(argv
[i
])) {
98 do_dotted_quad(argv
[i
]);