1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

telnetでBASIC認証を通す

Posted at

はじめて telnet を扱う人が雑に試してみた情報です。

スクリーンショット 2017-02-23 0.05.07.png

BASIC認証を要求するWebサーバを立てる

$ echo '<h1>Hello</h1>' > index.html
$ npm i -g serve
$ export SERVE_USER=admin
$ export SERVE_PASSWORD=secret
$ serve -a

   ┌──────────────────────────────────────────────────┐
   │                                                  │
   │   Serving!                                       │
   │                                                  │
   │   - Local:            http://localhost:3000      │
   │   - On Your Network:  http://192.168.0.21:3000   │
   │                                                  │
   │   Copied local address to clipboard!             │
   │                                                  │
   └──────────────────────────────────────────────────┘

telnetコマンドを使う

BASIC認証が有効なことを確認する

$ telnet localhost 3000
Trying ::1...
Connected to localhost.
Escape character is '^]'.

GET / HTTP/1.1

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Basic realm="User Visible Realm"
Content-Length: 13
Date: Wed, 22 Feb 2017 15:04:20 GMT
Connection: keep-alive

Access Denied

認証情報を付加してお返事をいただく

$ telnet localhost 3000
Trying ::1...
Connected to localhost.
Escape character is '^]'.

GET / HTTP/1.1
Authorization: Basic YWRtaW46c2VjcmV0  ★ココ★

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Accept-Ranges: bytes
Cache-Control: public, max-age=3
Last-Modified: Wed, 22 Feb 2017 14:37:44 GMT
ETag: W/"f-15a6641aac0"
Content-Length: 15
Vary: Accept-Encoding
Date: Wed, 22 Feb 2017 15:04:55 GMT
Connection: keep-alive

<h1>Hello</h1>

cf.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?