]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdemog.cc
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
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.
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.
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.
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.
28 #include "dnsparser.hh"
29 #include <boost/tuple/tuple.hpp>
30 #include <boost/tuple/tuple_comparison.hpp>
37 #include "namespaces.hh"
47 bool operator<(const struct Entry
& rhs
) const
49 return tie(ip
, port
, id
) < tie(rhs
.ip
, rhs
.port
, rhs
.id
);
54 typedef map
<Entry
, uint32_t> emap_t
;
57 int main(int argc
, char** argv
)
61 for(int n
=1 ; n
< argc
; ++n
) {
62 PcapPacketReader
pr(argv
[n
]);
65 while(pr
.getUDPPacket()) {
66 if(ntohs(pr
.d_udp
->uh_dport
)==53 && pr
.d_len
> 12) {
68 dnsheader
* dh
= (dnsheader
*) pr
.d_payload
;
73 MOADNSParser
mdp(false, (const char*)pr
.d_payload
, pr
.d_len
);
75 entry
.ip
= pr
.getSource();
76 entry
.port
= pr
.d_udp
->uh_sport
;
79 cout
<< "insert into dnsstats (source, port, id, query, qtype, tstampSec, tstampUsec, arcount) values ('" << entry
.ip
.toString() <<"', "<< ntohs(entry
.port
) <<", "<< ntohs(dh
->id
);
80 cout
<<", '"<<mdp
.d_qname
<<"', "<<mdp
.d_qtype
<<", " << pr
.d_pheader
.ts
.tv_sec
<<", " << pr
.d_pheader
.ts
.tv_usec
;
81 cout
<<", "<< ntohs(dh
->arcount
) <<");\n";
84 catch(const MOADNSException
&mde
) {
85 // cerr<<"error parsing packet: "<<mde.what()<<endl;
88 catch(std::exception
& e
) {
89 cerr
<< e
.what() << endl
;
97 for(emap_t::const_iterator i = ecount.begin(); i != ecount.end(); ++i) {
99 cout << U32ToIP(ntohl(i->first.ip)) <<":"<<ntohs(i->first.port)<<" -> "<<i->second <<endl;
104 catch(std::exception
& e
)
106 cerr
<<"Fatal: "<<e
.what()<<endl
;