1#!/usr/bin/perl
2#
3# $Id: chaos-query.pl 1640 2009-11-09 17:58:27Z gomor $
4#
5use strict;
6use warnings;
7
8use Getopt::Std;
9my %opts;
10getopts('d:i:I:v', \%opts);
11
12die "Usage: $0 -i dstIp [-I srcIp] [-d device] [-v]\n"
13   unless $opts{i};
14
15use Net::Packet;
16
17$Env->dev($opts{d}) if $opts{d};
18$Env->ip ($opts{I}) if $opts{I};
19$Env->debug(3)      if $opts{v};
20
21my $l3 = Net::Packet::IPv4->new(
22   protocol => NP_IPv4_PROTOCOL_UDP,
23   dst      => $opts{i},
24);
25
26my $l4 = Net::Packet::UDP->new(dst => 53);
27
28my $l7 = Net::Packet::Layer7->new(
29   data => "\x33\xde\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07\x76\x65".
30           "\x72\x73\x69\x6f\x6e\x04\x62\x69\x6e\x64\x00\x00\x10\x00\x03",
31);
32
33my $frame = Net::Packet::Frame->new(l3 => $l3, l4 => $l4, l7 => $l7);
34
35print "Request:\n";
36print $frame->l3->print, "\n";
37print $frame->l4->print, "\n";
38print $frame->l7->print, "\n";
39$frame->send;
40
41until ($Env->dump->timeout) {
42   if ($frame->recv) {
43      print "\nReply:\n";
44      print $frame->reply->l3->print, "\n";
45      print $frame->reply->l4->print, "\n";
46      print $frame->reply->l7->print, "\n";
47      last;
48   }
49}
50
51$Env->dump->stop;
52$Env->dump->clean;
53