]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsscan.cc
Merge pull request #7908 from omoerbeek/rec-4.1.14-changelog
[thirdparty/pdns.git] / pdns / dnsscan.cc
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 *
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.
8 *
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.
12 *
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.
17 *
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.
21 */
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 #include <bitset>
26 #include "statbag.hh"
27 #include "dnspcap.hh"
28 #include "sstuff.hh"
29 #include "anadns.hh"
30
31
32 #include <set>
33 #include <deque>
34
35 #include <boost/format.hpp>
36 #include <boost/utility.hpp>
37 #include <boost/multi_index_container.hpp>
38 #include <boost/multi_index/ordered_index.hpp>
39 #include <boost/multi_index/key_extractors.hpp>
40 #include <cctype>
41
42 #include "namespaces.hh"
43 using namespace ::boost::multi_index;
44 #include "namespaces.hh"
45 StatBag S;
46
47 void usage() {
48 cerr<<"syntax: dnsscan INFILE ..."<<endl;
49 }
50
51 int main(int argc, char** argv)
52 try
53 {
54 Socket sock(AF_INET, SOCK_DGRAM);
55
56 /*
57 IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1",
58 argc > 3 ? atoi(argv[3]) : 5300);
59
60 */
61
62 if(argc<2) {
63 usage();
64 exit(EXIT_SUCCESS);
65 }
66
67 for(int n=1; n < argc; ++n) {
68 if ((string) argv[n] == "--help") {
69 usage();
70 return EXIT_SUCCESS;
71 }
72
73 if ((string) argv[n] == "--version") {
74 cerr<<"dnsscan "<<VERSION<<endl;
75 return EXIT_SUCCESS;
76 }
77 }
78
79 unsigned int counts[256];
80 for(unsigned int n=0 ; n < 256; ++n)
81 counts[n]=0;
82
83 for(int n=1; n < argc; ++n) {
84 PcapPacketReader pr(argv[n]);
85
86 while(pr.getUDPPacket()) {
87 try {
88 MOADNSParser mdp(false, (const char*)pr.d_payload, pr.d_len);
89 if(mdp.d_qtype < 256)
90 counts[mdp.d_qtype]++;
91
92 }
93 catch(const MOADNSException &mde) {
94 cout<<"Error from remote "<<pr.getSource().toString()<<": "<<mde.what()<<"\n";
95 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
96 }
97 }
98 }
99 for(unsigned int n=0 ; n < 256; ++n) {
100 if(counts[n])
101 cout << n << "\t" << counts[n] << "\n";
102 }
103
104 }
105 catch(std::exception& e)
106 {
107 cout<<"Fatal: "<<e.what()<<endl;
108 }
109