First,
print(`...`);
simplifies to
system("...");
Since we no longer pipe out of nemesis
, that means we can easily pipe in. (If you want to do both, use IPC::Run3 or IPC::Run.)
my @cmd = ('nemesis',
'udp', '-S10.1.3.1', '-D10.1.3.100',
'-x53', '-y33333', '-P-' );
open(my $pipe, '|-', @cmd)
or die $!;
binmode($pipe);
print($pipe $payload);
close($pipe);
Of course, your code's $payload
doesn't actually contain the payload, but the hex representation of it. You could pack 'H*'
the whole thing, but I think the following is a better approach:
my $dnsId = int(rand(65536));
my $payload = pack('n H*',
$dnsId, '010000010000'. # 000000
'0000000003777777'. # 000010
'0f646e7370686973'. # 000020
'68696e676c616273'. # 000030
'03636f6d00000100'. # 000040
'01'); # 000050
Note that I changed 65535
to 65536
so make it possible to actually return 65535
.