]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dnsscan.cc
Merge pull request #14021 from Habbie/auth-lua-join-whitespace
[thirdparty/pdns.git] / pdns / dnsscan.cc
CommitLineData
12471842
PL
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 */
870a0fe4
AT
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
2353fffa
BH
25#include <bitset>
26#include "statbag.hh"
27#include "dnspcap.hh"
28#include "sstuff.hh"
29#include "anadns.hh"
30
2353fffa 31
2353fffa
BH
32#include <set>
33#include <deque>
34
35#include <boost/format.hpp>
36#include <boost/utility.hpp>
37#include <boost/multi_index_container.hpp>
38#include <boost/multi_index/ordered_index.hpp>
39#include <boost/multi_index/key_extractors.hpp>
40#include <cctype>
41
61b26744 42#include "namespaces.hh"
2353fffa 43using namespace ::boost::multi_index;
10f4eea8 44#include "namespaces.hh"
2353fffa
BH
45StatBag S;
46
050e6877 47static void usage() {
c18c244b
PL
48 cerr<<"syntax: dnsscan INFILE ..."<<endl;
49}
50
2353fffa
BH
51int main(int argc, char** argv)
52try
53{
528b753d 54 Socket sock(AF_INET, SOCK_DGRAM);
2353fffa 55
809fe23f 56 /*
2353fffa 57 IPEndpoint remote(argc > 2 ? argv[2] : "127.0.0.1",
232f0877 58 argc > 3 ? atoi(argv[3]) : 5300);
2353fffa 59
809fe23f 60 */
2353fffa 61
809fe23f 62 if(argc<2) {
c18c244b
PL
63 usage();
64 exit(EXIT_SUCCESS);
65 }
66
67 for(int n=1; n < argc; ++n) {
68 if ((string) argv[n] == "--help") {
69 usage();
70 return EXIT_SUCCESS;
71 }
72
73 if ((string) argv[n] == "--version") {
74 cerr<<"dnsscan "<<VERSION<<endl;
75 return EXIT_SUCCESS;
76 }
809fe23f 77 }
88338f52
BH
78
79 unsigned int counts[256];
80 for(unsigned int n=0 ; n < 256; ++n)
81 counts[n]=0;
809fe23f
BH
82
83 for(int n=1; n < argc; ++n) {
84 PcapPacketReader pr(argv[n]);
85
86 while(pr.getUDPPacket()) {
87 try {
27c0050c 88 MOADNSParser mdp(false, (const char*)pr.d_payload, pr.d_len);
4957a608
BH
89 if(mdp.d_qtype < 256)
90 counts[mdp.d_qtype]++;
88338f52 91
2353fffa 92 }
16ce7f18
JS
93 catch(const MOADNSException &mde) {
94 cout<<"Error from remote "<<pr.getSource().toString()<<": "<<mde.what()<<"\n";
232f0877 95 // sock.sendTo(string(pr.d_payload, pr.d_payload + pr.d_len), remote);
2353fffa 96 }
2353fffa
BH
97 }
98 }
88338f52
BH
99 for(unsigned int n=0 ; n < 256; ++n) {
100 if(counts[n])
101 cout << n << "\t" << counts[n] << "\n";
102 }
103
2353fffa 104}
adc10f99 105catch(std::exception& e)
2353fffa 106{
629eaf49 107 cout<<"Fatal: "<<e.what()<<endl;
2353fffa
BH
108}
109