1
0

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 1 year has passed since last update.

手っ取り早く Curl で hosts を変える方法 (メモ)

Last updated at Posted at 2024-02-21

/etc/hosts を書き換えなくても、curl コマンドだけで hosts を書き換えてリクエストを送る方法です。

頻繁に使っているけれど、毎日じゃないので、いつも忘れてググっているので、自分用メモです。

フォーマット

curl --resolve [ドメイン]:80:[IP アドレス] http://[ドメイン]
curl --resolve [ドメイン]:443:[IP アドレス] https://[ドメイン]

例1: 基本

example.com へのリクエストを 127.0.0.1 に向けてなげる

curl --resolve example.com:80:127.0.0.1 http://example.com

例2: 例1に加え Cookie "CONCRETE_LOGIN=1;CONCRETE=XXXXXXX" を追加

curl --cookie "CONCRETE_LOGIN=1;CONCRETE=XXXXXXX" --resolve example.com:80:127.0.0.1 http://example.com

例3: 例2に加え、出力をせず (-o /dev/null)、プログレスやエラーメッセージを出さず (-s) バイト数だけ表示する ( -s -w %{size_download})

curl -o /dev/null -s -w %{size_download} --cookie "CONCRETE_LOGIN=1;CONCRETE=XXXXXXX" --resolve example.com:80:127.0.0.1 http://example.com

例4: 例3に加え、Basic 認証 (ID が user、パスワードが pass) を追加

curl -o /dev/null -u user:pass -s -w %{size_download} --cookie "CONCRETE_LOGIN=1;CONCRETE=XXXXXXX" --resolve example.com:80:127.0.0.1 http://example.com
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?