]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsscan.cc
Merge pull request #2411 from pieterlexis/versionNumbers
[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 for(unsigned int i=0; i < mdp.d_qname.length(); ++i)
58 if(!isalnum(mdp.d_qname[i]) && mdp.d_qname[i]!='.' && mdp.d_qname[i]!='-' && mdp.d_qname[i]!='_') {
59 // cout<<mdp.d_qname<<"|"<<mdp.d_qtype<<"|"<<mdp.d_qclass<<"\n";
60 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
61 break;
62 }
63 if(mdp.d_qtype > 256 || mdp.d_qclass!=1 ) {
64 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
65
66 }
67 for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) {
68
69 }
70
71 }
72 catch(MOADNSException &e) {
73 cout<<"Error from remote "<<pr.getSource().toString()<<": "<<e.what()<<"\n";
74 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
75 }
76 }
77 }
78 for(unsigned int n=0 ; n < 256; ++n) {
79 if(counts[n])
80 cout << n << "\t" << counts[n] << "\n";
81 }
82
83 }
84 catch(std::exception& e)
85 {
86 cout<<"Fatal: "<<e.what()<<endl;
87 }
88