自動でHTTPリクエストをtelnetで送る

#!/bin/sh

#Send http request by telnet.

request="GET / HTTP/1.1"
host_header="Host: www.example.com"
dst=www.example.com
port=80

echo "$request"
echo "$host_header"
sleep 3

(
echo "$request"
echo "$host_header"
echo ""
sleep 5
) | telnet $dst $port

HTTPリクエストをtelnetで送信します。
"$request"と"$host_header"を2回ずつechoしているのは、リクエストヘッダとレスポンスヘッダの両方を標準出力に出力させるためです。
冒頭の echo 2行を省略すると、レスポンスヘッダのみが出力されます。

以上。

Leave a Reply

Your email address will not be published. Required fields are marked *