]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsscan.cc
Merge pull request #2684 from rubenk/recursor-docs-for-stats
[thirdparty/pdns.git] / pdns / dnsscan.cc
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #include <bitset>
5 #include "statbag.hh"
6 #include "dnspcap.hh"
7 #include "sstuff.hh"
8 #include "anadns.hh"
9
10 // this is needed because boost multi_index also uses 'L', as do we (which is sad enough)
11 #undef L
12
13 #include <set>
14 #include <deque>
15
16 #include <boost/format.hpp>
17 #include <boost/utility.hpp>
18 #include <boost/multi_index_container.hpp>
19 #include <boost/multi_index/ordered_index.hpp>
20 #include <boost/multi_index/key_extractors.hpp>
21 #include <cctype>
22
23 #include "namespaces.hh"
24 using namespace ::boost::multi_index;
25 #include "namespaces.hh"
26 StatBag S;
27
28 int main(int argc, char** argv)
29 try
30 {
31 Socket sock(AF_INET, SOCK_DGRAM);
32
33 /*
34 IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1",
35 argc > 3 ? atoi(argv[3]) : 5300);
36
37 */
38
39 if(argc<2) {
40 cerr<<"Syntax: dnsscan file1 [file2 ..] "<<endl;
41 exit(1);
42 }
43
44 unsigned int counts[256];
45 for(unsigned int n=0 ; n < 256; ++n)
46 counts[n]=0;
47
48 for(int n=1; n < argc; ++n) {
49 PcapPacketReader pr(argv[n]);
50
51 while(pr.getUDPPacket()) {
52 try {
53 MOADNSParser mdp((const char*)pr.d_payload, pr.d_len);
54 if(mdp.d_qtype < 256)
55 counts[mdp.d_qtype]++;
56
57 }
58 catch(MOADNSException &e) {
59 cout<<"Error from remote "<<pr.getSource().toString()<<": "<<e.what()<<"\n";
60 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
61 }
62 }
63 }
64 for(unsigned int n=0 ; n < 256; ++n) {
65 if(counts[n])
66 cout << n << "\t" << counts[n] << "\n";
67 }
68
69 }
70 catch(std::exception& e)
71 {
72 cout<<"Fatal: "<<e.what()<<endl;
73 }
74