]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsscan.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * In addition, for the avoidance of any doubt, permission is granted to
10 * link this program with OpenSSL and to (re)distribute the binaries
11 * produced as the result of such linking.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 // this is needed because boost multi_index also uses 'L', as do we (which is sad enough)
37 #include <boost/format.hpp>
38 #include <boost/utility.hpp>
39 #include <boost/multi_index_container.hpp>
40 #include <boost/multi_index/ordered_index.hpp>
41 #include <boost/multi_index/key_extractors.hpp>
44 #include "namespaces.hh"
45 using namespace ::boost::multi_index
;
46 #include "namespaces.hh"
50 cerr
<<"syntax: dnsscan INFILE ..."<<endl
;
53 int main(int argc
, char** argv
)
56 Socket
sock(AF_INET
, SOCK_DGRAM
);
59 IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1",
60 argc > 3 ? atoi(argv[3]) : 5300);
69 for(int n
=1; n
< argc
; ++n
) {
70 if ((string
) argv
[n
] == "--help") {
75 if ((string
) argv
[n
] == "--version") {
76 cerr
<<"dnsscan "<<VERSION
<<endl
;
81 unsigned int counts
[256];
82 for(unsigned int n
=0 ; n
< 256; ++n
)
85 for(int n
=1; n
< argc
; ++n
) {
86 PcapPacketReader
pr(argv
[n
]);
88 while(pr
.getUDPPacket()) {
90 MOADNSParser
mdp((const char*)pr
.d_payload
, pr
.d_len
);
92 counts
[mdp
.d_qtype
]++;
95 catch(MOADNSException
&e
) {
96 cout
<<"Error from remote "<<pr
.getSource().toString()<<": "<<e
.what()<<"\n";
97 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
101 for(unsigned int n
=0 ; n
< 256; ++n
) {
103 cout
<< n
<< "\t" << counts
[n
] << "\n";
107 catch(std::exception
& e
)
109 cout
<<"Fatal: "<<e
.what()<<endl
;