forked from sipa/bitcoin-seeder
-
Notifications
You must be signed in to change notification settings - Fork 18
/
test.pl
68 lines (54 loc) · 1.29 KB
/
test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl
use warnings FATAL => 'all';
use threads;
use threads::shared;
use bytes;
use IO::Socket;
use strict;
my @dom = ("seed","bitcoin","sipa","be");
my $run :shared = 1;
sub go {
my ($idx) = @_;
my $runs = 0;
my $sock = IO::Socket::INET->new(
Proto => 'udp',
PeerPort => 53,
PeerAddr => "vps.sipa.be",
) or die "Could not create socket: $!\n";
while($run) {
my $id = int(rand(65536));
my $qr = 0;
my $opcode = 0;
my $aa = 0;
my $tc = 0;
my $rd = 0;
my $ra = 0;
my $z = 0;
my $rcode = 0;
my $qdcount = 1;
my $ancount = 0;
my $nscount = 0;
my $arcount = 0;
my $header = pack('nnnnnn',$id,1*$qr + 2*$opcode + 32*$aa + 64*$tc + 128*$rd + 256*$ra + 512*$z + 4096*$rcode, $qdcount, $ancount, $nscount, $arcount);
my $qtype = 1; # A record
my $qclass = 1; # IN class
my $query = (join("", map { chr(length($_)) . $_ } (@dom,""))) . pack('nn',$qtype,$qclass);
my $msg = $header . $query;
$sock->send($msg);
my $resp;
$runs++ if ($sock->recv($resp, 512, 0));
# $sock->close();
}
return $runs;
}
my @threads;
for my $i (0..500) {
$threads[$i] = threads->create(\&go, $i);
}
sleep 10;
$run=0;
my $runs = 0;
foreach my $thr (@threads) {
$runs += $thr->join();
}
print "$runs runs\n";