Skip to content

Instantly share code, notes, and snippets.

@x-way
Created December 4, 2015 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x-way/caf03da77fe2cc83b6bd to your computer and use it in GitHub Desktop.
Save x-way/caf03da77fe2cc83b6bd to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# Written by Andreas Jaggi <andreas.jaggi@waterwave.ch> in December 2015
#
use strict;
use warnings;
use nflog;
use NetPacket::IP qw(IP_PROTO_UDP);
use NetPacket::UDP;
use Socket qw(AF_INET AF_INET6);
use Net::DNS::Packet;
my $l;
sub callback {
my ($payload) = @_;
if ($payload) {
my $ip_obj = NetPacket::IP->decode($payload->get_data());
if ($ip_obj->{proto} == IP_PROTO_UDP) {
my $packet = new Net::DNS::Packet(\NetPacket::UDP->decode($ip_obj->{data})->{data});
if($packet->header->qr){
foreach my $answer ( $packet->answer ) {
print "answer(".$answer->type.")[".$answer->ttl."]: ".$answer->name." -> ".$answer->rdstring."\n";
}
}
}
}
return 0;
}
sub cleanup {
$l->unbind(AF_INET);
$l->close();
}
sub main {
$l = new nflog::log();
$SIG{INT} = "cleanup";
$l->set_callback(\&callback);
$l->fast_open(123,AF_INET);
$l->try_run();
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment