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
|
#!/usr/local/bin/perl
# tcp-banger.pl
#
# Duane Wessels, Dec 1995
#
# Usage: tcp-banger.pl [host [port]] < url-list
#
# Sends a continuous stream of HTTP proxy requests to a cache. Stdin is a
# list of URLs to request. Run N of these at the same time to simulate a
# heavy client load.
#
# NOTE: does not simulate "real-world" events such as aborted requests
# (connections) and other network problems.
$|=1;
$host=(shift || 'localhost') ;
$port=(shift || '3128') ;
require 'sys/socket.ph';
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname("tcp");
($fqdn, $aliases, $type, $len, $thataddr) = gethostbyname($host);
$thissock = pack($sockaddr, &AF_INET, 0, "\0\0\0\0");
$that = pack($sockaddr, &AF_INET, $port, $thataddr);
while (<>) {
chop ($url = $_);
die "socket: $!\n" unless
socket (SOCK, &AF_INET, &SOCK_STREAM, $proto);
die "bind: $!\n" unless
bind (SOCK, $thissock);
die "$host:$port: $!\n" unless
connect (SOCK, $that);
select (SOCK); $| = 1;
select (STDOUT);
print SOCK "GET $url HTTP/1.0\r\nAccept: */*\r\n\r\n";
$_ = <SOCK>;
($ver,$code,$junk) = split;
printf "%s %s\n", $code ? $code : 'FAIL', $url;
1 while (read(SOCK,$_,4096));
close SOCK;
}
|