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