]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsscan.cc
Merge pull request #4305 from rgacogne/dnsdist-lua-anon
[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 // this is needed because boost multi_index also uses 'L', as do we (which is sad enough)
32 #undef L
33
34 #include <set>
35 #include <deque>
36
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>
42 #include <cctype>
43
44 #include "namespaces.hh"
45 using namespace ::boost::multi_index;
46 #include "namespaces.hh"
47 StatBag S;
48
49 void usage() {
50 cerr<<"syntax: dnsscan INFILE ..."<<endl;
51 }
52
53 int main(int argc, char** argv)
54 try
55 {
56 Socket sock(AF_INET, SOCK_DGRAM);
57
58 /*
59 IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1",
60 argc > 3 ? atoi(argv[3]) : 5300);
61
62 */
63
64 if(argc<2) {
65 usage();
66 exit(EXIT_SUCCESS);
67 }
68
69 for(int n=1; n < argc; ++n) {
70 if ((string) argv[n] == "--help") {
71 usage();
72 return EXIT_SUCCESS;
73 }
74
75 if ((string) argv[n] == "--version") {
76 cerr<<"dnsscan "<<VERSION<<endl;
77 return EXIT_SUCCESS;
78 }
79 }
80
81 unsigned int counts[256];
82 for(unsigned int n=0 ; n < 256; ++n)
83 counts[n]=0;
84
85 for(int n=1; n < argc; ++n) {
86 PcapPacketReader pr(argv[n]);
87
88 while(pr.getUDPPacket()) {
89 try {
90 MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
91 if(mdp.d_qtype < 256)
92 counts[mdp.d_qtype]++;
93
94 }
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);
98 }
99 }
100 }
101 for(unsigned int n=0 ; n < 256; ++n) {
102 if(counts[n])
103 cout << n << "\t" << counts[n] << "\n";
104 }
105
106 }
107 catch(std::exception& e)
108 {
109 cout<<"Fatal: "<<e.what()<<endl;
110 }
111