-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrandomvhost.pl
More file actions
75 lines (66 loc) · 1.8 KB
/
randomvhost.pl
File metadata and controls
75 lines (66 loc) · 1.8 KB
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
69
70
71
72
73
74
75
#!/usr/bin/perl
use strict;
use warnings;
use threads;
use threads::shared;
use Furl;
use Perl::Unsafe::Signals;
my $quit : shared = 0;
#my %count;
sub ctrlc { $quit = 1; }
$SIG{INT} = \&ctrlc;
my $start_time = time;
my $numthreads = $ARGV[0];
print "num threads: $numthreads, pid: $$\n";
print "Hit ctrl-c to end\n";
sub fetch {
my $tid = shift;
# my $furl = Furl::HTTP->new(agent => 'Furl/0.31',timeout => 10, Host => "$string.arreyder.com");
my $start_time = time;
my %count;
while(!$quit) {
my @chars = ("A".."Z", "a".."z");
my $string;
$string .= $chars[rand @chars] for 1..8;
my $furl = Furl::HTTP->new(agent => 'Furl/0.31',timeout => 10, Host => "$string.arreyder.com");
my $url = "https://$string.arreyder.com/";
chomp $url;
# print "start $tid: $url\n";
my ($ver, $code, $msg, $headers, $body) = $furl->get($url);
my $size = length $body;
if ($count{$code}) {
$count{$code}++ }
else {
$count{$code} = 1;
}
print "code: $code, finish $tid: $url, $size bytes, message:$msg\r"; # unless ($code eq "404" || $code eq "200");
}
print "\n\n\nStats per thread\n";
&emit($start_time,$tid,\%count);
}
sub emit {
my $start_time = $_[0];
my $tid = $_[1];
my %count = %{$_[2]};
my $end_time = time;
my $elapsed_time = $end_time - $start_time;
my $data_string;
if (%count) {
foreach my $key (keys(%count)) {
my $rate = $count{$key} / $elapsed_time;
$data_string .= "Thread:$tid Status:$key Rate:" . sprintf("%.3f",$rate) ." Total:" . $count{$key} . " Duration:$elapsed_time seconds\n";
}
print "\n" . $data_string;
}
return;
}
my @threads;
for(my $i = 0; $i < $numthreads; ++$i) {
my $thread = threads->create(\&fetch,$i);
push(@threads, $thread);
}
UNSAFE_SIGNALS {
foreach (@threads) {
$_->join();
}
}