]>
git.ipfire.org Git - thirdparty/squid.git/blob - scripts/tcp-banger.pl
3 ## Copyright (C) 1996-2016 The Squid Software Foundation and contributors
5 ## Squid software is distributed under GPLv2+ license and includes
6 ## contributions from numerous individuals and organizations.
7 ## Please see the COPYING and CONTRIBUTORS files for details.
12 # Duane Wessels, Dec 1995
14 # Usage: tcp-banger.pl [host [port]] < url-list
16 # Sends a continuous stream of HTTP proxy requests to a cache. Stdin is a
17 # list of URLs to request. Run N of these at the same time to simulate a
20 # NOTE: does not simulate "real-world" events such as aborted requests
21 # (connections) and other network problems.
25 $host=(shift || 'localhost') ;
26 $port=(shift || '3128') ;
28 require 'sys/socket.ph';
30 $sockaddr = 'S n a4 x8';
31 ($name, $aliases, $proto) = getprotobyname("tcp");
32 ($fqdn, $aliases, $type, $len, $thataddr) = gethostbyname($host);
33 $thissock = pack($sockaddr, &AF_INET
, 0, "\0\0\0\0");
34 $that = pack($sockaddr, &AF_INET
, $port, $thataddr);
39 die "socket: $!\n" unless
40 socket (SOCK
, &AF_INET
, &SOCK_STREAM
, $proto);
41 die "bind: $!\n" unless
42 bind (SOCK
, $thissock);
43 die "$host:$port: $!\n" unless
44 connect (SOCK
, $that);
45 select (SOCK
); $| = 1;
48 print SOCK
"GET $url HTTP/1.0\r\nAccept: */*\r\n\r\n";
50 ($ver,$code,$junk) = split;
51 printf "%s %s\n", $code ?
$code : 'FAIL', $url;
52 1 while (read(SOCK
,$_,4096));