~ubuntu-branches/ubuntu/maverick/pdns/maverick-updates

« back to all changes in this revision

Viewing changes to pdns/dnsscan.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matthijs Mohlmann, Matthijs Mohlmann, Christoph Haas
  • Date: 2007-04-15 23:23:39 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070415232339-5x3scc8gx04e50um
Tags: 2.9.21-1
[ Matthijs Mohlmann ]
* New upstream release. (Closes: #420294)
* Remove meta pdns package.
* Added new sqlite3 backend package.
* Months and minutes where mixed up. (Closes: #406462)
* Case sensitivity in bind backend caused PowerDNS to not serve a certain
  zone. (Closes: #406461)
* Bind backend forgot about zones on a notify. (Closes: #398213)

[ Christoph Haas ]
* Documented incorporated backend bind. (Closes: #415471)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
using namespace boost;
 
21
using namespace ::boost::multi_index;
 
22
using namespace std;
 
23
StatBag S;
 
24
 
 
25
int main(int argc, char** argv)
 
26
try
 
27
{
 
28
  Socket sock(InterNetwork, Datagram);
 
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(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(exception& e)
 
82
{
 
83
  cout<<"Fatal: "<<e.what()<<endl;
 
84
}
 
85