<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/local/bin/perl
#
## Copyright (C) 1996-2021 The Squid Software Foundation and contributors
##
## Squid software is distributed under GPLv2+ license and includes
## contributions from numerous individuals and organizations.
## Please see the COPYING and CONTRIBUTORS files for details.
##

# tcp-banger.pl	
#
# Duane Wessels, Dec 1995
#
# Usage: tcp-banger.pl [host [port]] &lt; 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, &amp;AF_INET, 0, "\0\0\0\0");
$that = pack($sockaddr, &amp;AF_INET, $port, $thataddr);

while (&lt;&gt;) {
	chop ($url = $_);

	die "socket: $!\n" unless
        	socket (SOCK, &amp;AF_INET, &amp;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";
	$_ = &lt;SOCK&gt;;
	($ver,$code,$junk) = split;
	printf "%s %s\n", $code ? $code : 'FAIL', $url;
	1 while (read(SOCK,$_,4096));
	close SOCK;
}
</pre></body></html>