]>
Commit | Line | Data |
---|---|---|
090089c4 | 1 | #!/usr/local/bin/perl |
a151895d | 2 | # |
5b74111a | 3 | ## Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
a151895d AJ |
4 | ## |
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. | |
8 | ## | |
090089c4 | 9 | |
10 | # tcp-banger.pl | |
11 | # | |
12 | # Duane Wessels, Dec 1995 | |
13 | # | |
14 | # Usage: tcp-banger.pl [host [port]] < url-list | |
15 | # | |
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 | |
18 | # heavy client load. | |
19 | # | |
20 | # NOTE: does not simulate "real-world" events such as aborted requests | |
21 | # (connections) and other network problems. | |
22 | ||
23 | $|=1; | |
24 | ||
25 | $host=(shift || 'localhost') ; | |
26 | $port=(shift || '3128') ; | |
27 | ||
505893c4 | 28 | require 'sys/socket.ph'; |
090089c4 | 29 | |
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); | |
35 | ||
36 | while (<>) { | |
37 | chop ($url = $_); | |
38 | ||
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; | |
46 | select (STDOUT); | |
47 | ||
f68236fd | 48 | print SOCK "GET $url HTTP/1.0\r\nAccept: */*\r\n\r\n"; |
090089c4 | 49 | $_ = <SOCK>; |
50 | ($ver,$code,$junk) = split; | |
51 | printf "%s %s\n", $code ? $code : 'FAIL', $url; | |
52 | 1 while (read(SOCK,$_,4096)); | |
53 | close SOCK; | |
54 | } |