curlのお勉強
疑問~curlの使い方、使い道~
仕事でほんとたまーに出てくる「curl」。
正直こいつがなんなのかよくわかっていない。
curl <対象url> で使うというぐらいの理解なのでちょっと調べてみた。
どうやらhttpリクエストを行うものらしい。
本気で調査するならデベロッパーツールとかを使うらしいが、軽く生存確認するぐらいなら選択肢に入ってくるようだ。
サーバ上からできるのもポイントか。
いや待てよ・・・、これ使えばできないと思っていたURL監視できそうだな。
curl -s http://diary.hdora.tokyo -o /dev/null -w '%{http_code}\n' curl -s https://diary.hdora.tokyo -o /dev/null -w '%{http_code}\n'
推しオプション~-Lと-Iと-v~
オプションの中で便利らいいのは
-L -s -o とのこと。
わたしは-Lと-Iと-vを推すwww。
Lオプション リダイレクト先のcurl結果を返す
Iオプション HTTPレスポンスヘッダー表示
vオプション 詳細表示
作業記録~curlを使ってみた~
・Lオプション curl http://diary.hdora.tokyo ----- <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>CloudFront</center> </body> </html> ----- curl -L http://diary.hdora.tokyo ----- <!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>15年間漫画家志望でしたが諦めました | 中学生からの15年間、30歳ごろまで漫画家志望(ニート)だった男のブログ。失った15年を取り戻す為、新しいことに毎日挑戦していきます。</title> <link rel='dns-prefetch' href='//s.w.org' /> <link rel="alternate" type="application/rss+xml" title="15年間漫画家志望でしたが諦めました » フィード" href="https://diary.hdora.tokyo/?feed=rss2" /> <link rel="alternate" type="application/rss+xml" title="15年間漫画家志望でしたが諦めました » コメントフィード" href="https://diary.hdora.tokyo/?feed=comments-rss2" /> <meta name="description" content="中学生からの15年間、30歳ごろまで漫画家志望(ニート)だった男のブログ。失った15年を取り戻す為、新しいことに毎日挑戦していきます。" /> <script type="text/javascript"> : : ----- ・Iオプション curl -I http://diary.hdora.tokyo ----- HTTP/1.1 301 Moved Permanently Server: CloudFront Date: Mon, 10 Aug 2020 06:50:44 GMT Content-Type: text/html Content-Length: 183 Connection: keep-alive Location: https://diary.hdora.tokyo/ X-Cache: Redirect from cloudfront Via: 1.1 1bb0e0c2255db96cb164e434dd58c436.cloudfront.net (CloudFront) X-Amz-Cf-Pop: NRT12-C3 X-Amz-Cf-Id: uPCryFh9ThRrk4r-VDRR2fEklGSDkWd5ZpJhfp8levWUutJfdBSw5A== ----- curl -I https://diary.hdora.tokyo ----- HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Connection: keep-alive Date: Mon, 10 Aug 2020 05:55:05 GMT Server: Apache X-FRAME-OPTIONS: SAMEORIGIN Link: <https://diary.hdora.tokyo/index.php?rest_route=/>; rel="https://api.w.org/" X-Cache: Hit from cloudfront Via: 1.1 d930c4e4b6bd1abceb94d9d7f03e8e5f.cloudfront.net (CloudFront) X-Amz-Cf-Pop: NRT12-C3 X-Amz-Cf-Id: wW3nR4nG8cvEjhobM16HtiyQQI22VDp_X3oLazsrgKkwTzXAQ7Qseg== Age: 3339 ----- ・vオプション curl -v http://diary.hdora.tokyo * About to connect() to diary.hdora.tokyo port 80 (#0) * Trying 13.249.171.33... * Connected to diary.hdora.tokyo (13.249.171.33) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: diary.hdora.tokyo > Accept: */* > < HTTP/1.1 301 Moved Permanently < Server: CloudFront < Date: Mon, 10 Aug 2020 07:01:38 GMT < Content-Type: text/html < Content-Length: 183 < Connection: keep-alive < Location: https://diary.hdora.tokyo/ < X-Cache: Redirect from cloudfront < Via: 1.1 04c2f7c6be96060d3defd0bb02b9dbde.cloudfront.net (CloudFront) < X-Amz-Cf-Pop: NRT12-C3 < X-Amz-Cf-Id: C6LMlzNbN-ffJ3JqXnbfj76RjyYeYbmjJQi3hFqgwWOIJFzLZJTurA== < <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>CloudFront</center> </body> </html> * Connection #0 to host diary.hdora.tokyo left intact curl -v https://diary.hdora.tokyo ----- * Trying 13.249.171.97... * Connected to diary.hdora.tokyo (13.249.171.97) port 443 (#0) * Initializing NSS with certpath: sql:/etc/pki/nssdb * CAfile: /etc/pki/tls/certs/ca-bundle.crt CApath: none * SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 * Server certificate: * subject: CN=hdora.tokyo * start date: May 15 00:00:00 2020 GMT * expire date: Jun 15 12:00:00 2021 GMT * common name: hdora.tokyo * issuer: CN=Amazon,OU=Server CA 1B,O=Amazon,C=US > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: diary.hdora.tokyo > Accept: */* > < HTTP/1.1 200 OK < Content-Type: text/html; charset=UTF-8 < Transfer-Encoding: chunked < Connection: keep-alive < Date: Mon, 10 Aug 2020 07:01:31 GMT < Server: Apache < X-FRAME-OPTIONS: SAMEORIGIN < Link: <https://diary.hdora.tokyo/index.php?rest_route=/>; rel="https://api.w.org/" < X-Cache: Hit from cloudfront < Via: 1.1 d9af3f176cedc4b9ece3a6c542e34cc1.cloudfront.net (CloudFront) < X-Amz-Cf-Pop: NRT12-C3 < X-Amz-Cf-Id: nITp9JWrvN3XDUUKwy3EKO-7zns8bwEH2AWrXGzV8b78RMyCVxTrgg== < Age: 76 < : : -----
感想
Lオプションはいまいちかな。
結局httpsでcurl仕直せばいいわけだし・・・。
Iオプションであればステータスとれるな。
vオプションだとcloudfrontとかサーバのipアドレスとかもバレてしまうわけか。
ロードバランサーを間に噛ませた場合、絶対にオリジンのサーバIPはバレないのだろうか。