cURLの使えそうなオプションメモ

HEAD リクエストする

curl -I https://works.kamityping.com/post/2018/harmonize-ja.html

HTTP/1.1 200 OK
Date: Wed, 23 May 2018 13:17:41 GMT
Server: Apache
Last-Modified: Wed, 23 May 2018 12:16:12 GMT
ETag: "1a0014-3b73-56cde8024fb00"
Accept-Ranges: bytes
Content-Length: 15219
Vary: Accept-Encoding,User-Agent
Connection: close
Content-Type: text/html

Googleをみてみる。

curl -I https://www.google.co.jp/

HTTP/2 200
birthtime: "2018-05-23"
mtime: "2018-05-23"
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=Shift_JIS
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
server: gws
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
set-cookie: 1P_JAR=2018-05-23-13; expires=Fri, 22-Jun-2018 13:19:03 GMT; path=/; domain=.google.co.jp
set-cookie: NID=130=Z1_NdyJN6fhaDsLmr68L6XcQoGc4mxeJKTNmgJ4HyyVF1jlRuxdbZ1wnDgei5HmJdYoa2xof4SJvFUx2DNQrwz2Kt5KLvcVILbN9MMft7b33NTSjeaYJJ1VH-7tCxr0y; expires=Thu, 22-Nov-2018 13:19:03 GMT; path=/; domain=.google.co.jp; HttpOnly
alt-svc: hq=":443"; ma=2592000; quic=51303433; quic=51303432; quic=51303431; quic=51303339; quic=51303335,quic=":443"; ma=2592000; v="43,42,41,39,35"
accept-ranges: none
vary: Accept-Encoding

リクエストヘッダ、レスポンスヘッダ、SSL/TLS handshakeをみる

ヘッダだけ表示させるために、標準出力は/dev/nullに捨てている

参考: https://qiita.com/takc923/items/1b508bb370c78b7a9d44

curl --verbose https://google.com 1> /dev/null

curl --verbose https://works.kamityping.com/post/2018/harmonize-ja.html 1> /dev/null

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 133.242.155.84...
* TCP_NODELAY set
* Connected to works.kamityping.com (133.242.155.84) port 443 (#0)
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.2 (IN), TLS handshake, Server hello (2):
{ [93 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [2746 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
{ [1 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: CN=works.kamityping.com
*  start date: May 20 07:08:05 2018 GMT
*  expire date: Aug 18 07:08:05 2018 GMT
*  subjectAltName: host "works.kamityping.com" matched cert's "works.kamityping.com"
*  issuer: C=US; O=Let's Encrypt; CN=Let's Encrypt Authority X3
*  SSL certificate verify ok.
> GET /post/2018/harmonize-ja.html HTTP/1.1
> Host: works.kamityping.com
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 23 May 2018 13:25:06 GMT
< Server: Apache
< Last-Modified: Wed, 23 May 2018 12:16:12 GMT
< ETag: "1a0014-3b73-56cde8024fb00"
< Accept-Ranges: bytes
< Content-Length: 15219
< Vary: Accept-Encoding,User-Agent
< Connection: close
< Content-Type: text/html
<
{ [15219 bytes data]
100 15219  100 15219    0     0  36943      0 --:--:-- --:--:-- --:--:-- 36939
* Closing connection 0
* TLSv1.2 (OUT), TLS alert, Client hello (1):
} [2 bytes data]

ユーザーエージェントを偽装する

curl --verbose -A  "Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1" https://www.google.com 1> /dev/null