]>
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"
35 #include "namespaces.hh"
45 bool operator<(const struct Entry
& rhs
) const
47 return std::tie(ip
, port
, id
) < std::tie(rhs
.ip
, rhs
.port
, rhs
.id
);
52 typedef map
<Entry
, uint32_t> emap_t
;
55 int main(int argc
, char** argv
)
59 for(int n
=1 ; n
< argc
; ++n
) {
60 PcapPacketReader
pr(argv
[n
]);
63 while(pr
.getUDPPacket()) {
64 if(ntohs(pr
.d_udp
->uh_dport
)==53 && pr
.d_len
> 12) {
66 dnsheader
* dh
= (dnsheader
*) pr
.d_payload
;
71 MOADNSParser
mdp(false, (const char*)pr
.d_payload
, pr
.d_len
);
73 entry
.ip
= pr
.getSource();
74 entry
.port
= pr
.d_udp
->uh_sport
;
77 cout
<< "insert into dnsstats (source, port, id, query, qtype, tstampSec, tstampUsec, arcount) values ('" << entry
.ip
.toString() <<"', "<< ntohs(entry
.port
) <<", "<< ntohs(dh
->id
);
78 cout
<<", '"<<mdp
.d_qname
<<"', "<<mdp
.d_qtype
<<", " << pr
.d_pheader
.ts
.tv_sec
<<", " << pr
.d_pheader
.ts
.tv_usec
;
79 cout
<<", "<< ntohs(dh
->arcount
) <<");\n";
82 catch(const MOADNSException
&mde
) {
83 // cerr<<"error parsing packet: "<<mde.what()<<endl;
86 catch(std::exception
& e
) {
87 cerr
<< e
.what() << endl
;
95 for(emap_t::const_iterator i = ecount.begin(); i != ecount.end(); ++i) {
97 cout << U32ToIP(ntohl(i->first.ip)) <<":"<<ntohs(i->first.port)<<" -> "<<i->second <<endl;
102 catch(std::exception
& e
)
104 cerr
<<"Fatal: "<<e
.what()<<endl
;