cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

os:linux:command:curl.html



Linux Commands#Network

curl - How to use curl command on Linux

Help for Curl Command

# curl -h

 -i, --include       Include protocol headers in the output (H/F)
 -I, --head          Show document info only
 -o, --output FILE   Write output to <file> instead of stdout
 -O, --remote-name   Write output to a file named as the remote file
     --remote-name-all Use the remote file name for all URLs
 -x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port
     --proxy-ntlm    Use NTLM authentication on the proxy (H)
 -U, --proxy-user USER[:PASSWORD]  Proxy user and password
 -L, --location      Follow redirects (H)

# man curl
       -I, --head
              (HTTP/FTP/FILE) Fetch the HTTP-header only!

       -x, --proxy <[protocol://][user:password@]proxyhost[:port]>
              Use the specified HTTP proxy. If the port number is not specified, it is assumed at port 1080.

       -i, --include
              (HTTP)  Include  the HTTP-header in the output. The HTTP-header includes things like
              server-name, date of the docu‐ment, HTTP-version and more...

       -k, --insecure
              (SSL)  This  option  explicitly allows curl to perform "insecure" SSL connections and transfers.

       -L, --location
              (HTTP/HTTPS)  If  the  server reports that the requested page has moved to a different 
              location (indicated with a Location: header and a 3XX response code), this option will
              make curl redo the request on the new place. 

      -J, --remote-header-name
              (HTTP)  This  option  tells  the -O, --remote-name option to use the server-specified
              Content-Disposition filename instead of extracting a filename from the URL.

       -o, --output <file>
              Write  output  to  <file>  instead  of  stdout. If you are using {} or [] to fetch
              multiple documents, you can use '#' followed by a number in the


       -O, --remote-name
              Write output to a local file named like the remote file we get. (Only the file part of
              the remote file is used, the path is cut off.)

              The remote file name to use for saving is extracted from the given URL, nothing else.

       -U, --proxy-user <user:password>
              Specify the user name and password to use for proxy authentication.

       -H, --header <header>
              (HTTP)  Extra  header  to  use when getting a web page.


       -1, --tlsv1
              (SSL)  Forces curl to use TLS version 1.x when negotiating with a remote TLS server.
              You can use options --tlsv1.0, --tlsv1.1, and --tlsv1.2 to control the TLS version
              more precisely (if the SSL backend in  use supports such a level of control).

       -2, --sslv2
              (SSL) Forces curl to use SSL version 2 when negotiating with a remote SSL server.

       -3, --sslv3
              (SSL) Forces curl to use SSL version 3 when negotiating with a remote SSL server.

       --tlsv1.0
              (SSL) Forces curl to use TLS version 1.0 when negotiating with a remote TLS server. 
              (Added in 7.34.0)

       --tlsv1.1
              (SSL) Forces curl to use TLS version 1.1 when negotiating with a remote TLS server. 
              (Added in 7.34.0)

       --tlsv1.2
              (SSL) Forces curl to use TLS version 1.2 when negotiating with a remote TLS server. 
              (Added in 7.34.0)


Example curl command

Download Files

curl -O http://example.com/images/test.jpg
curl -L -O https://packages.chef.io/stable/el/7/chefdk-0.16.28-1.el7.x86_64.rpm
curl -LOJ  'https://docs.google.com/uc?id=0B3X9GlR6EmbnQ0FtZmJJUXEyRTA&export=download'


Only HTTP Header

# curl -I http://www.uniqlo.com/
HTTP/1.1 302 Moved Temporarily
Server: AkamaiGHost
Content-Length: 0
Location: http://www.uniqlo.com/jp/
Date: Tue, 28 Jul 2015 15:39:01 GMT
Connection: keep-alive



How to check remote IP Address.

# curl -v -I http://www.uniqlo.com/
* About to connect() to www.uniqlo.com port 80
*   Trying 104.78.208.101... connected
* Connected to www.uniqlo.com (104.78.208.101) port 80
> HEAD / HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: www.uniqlo.com
> Accept: */*
> 
< HTTP/1.1 302 Moved Temporarily
HTTP/1.1 302 Moved Temporarily
< Server: AkamaiGHost
Server: AkamaiGHost
< Content-Length: 0
Content-Length: 0
< Location: http://www.uniqlo.com/jp/
Location: http://www.uniqlo.com/jp/
< Cache-Control: max-age=0
Cache-Control: max-age=0
< Expires: Sun, 22 Jan 2017 00:53:04 GMT
Expires: Sun, 22 Jan 2017 00:53:04 GMT
< Date: Sun, 22 Jan 2017 00:53:04 GMT
Date: Sun, 22 Jan 2017 00:53:04 GMT
< Connection: keep-alive
Connection: keep-alive

* Connection #0 to host www.uniqlo.com left intact
* Closing connection #0


Use a Proxy

# curl --proxy http://proxy.example.com:8080 http://example.com/
# curl -U user01:password01 --proxy http://proxy.example.com:8080 http://example.com/


Use NTML

curl -U : --proxy-ntlm --proxy PROXYSERVER:PORT http://example.com/

you can force curl to pick up the user name and password from your environment by simply specifying a single colon with this option: "-U :".

curl -U USER:PASSWORD --proxy-ntlm --proxy PROXYSERVER:PORT http://example.com/
curl -I --ntlm --user DOMAIN\\Administrator:Password "http://example.com"
curl -u 'DOMAINNAME\USERNAME':pass  --ntlm  http://www.example.com/


Authentication(Basic Authentication)

curl --anyauth --user user01:password http://www.example.com/


Check Speed

#curl -s -o /dev/null -w "%{time_total}\n" http://www.example.com/
0.008
#
#cat curl-format 
    time_namelookup:  %{time_namelookup}\n
       time_connect:  %{time_connect}\n
 time_starttransfer:  %{time_starttransfer}\n
                    ----------\n
         time_total:  %{time_total}\n
#
# curl -s -o /dev/null -w @curl-format https://www.exaple.com/
    time_namelookup:  0.035
       time_connect:  0.204
 time_starttransfer:  0.759
                    ----------
         time_total:  0.759


Self Sign SSL Cert

curl -–cacert server.crt  https://xx.xx.xx.xx/


Client SSL Cert

curl --key ./client.key --cert ./client.cer https://xx.xxx.xx/


SSL/TLV Version Options

curl --sslv3 -I -v https://example.com/
curl --tlsv1.0 -I -v https://example.com/
curl --tlsv1.1 -I -v https://example.com/


Request Header & Response Header

#curl  --verbose http://www.uniqlo.com/ 1> /dev/null
* STATE: INIT => CONNECT handle 0x80048230; line 1075 (connection #-5000)
* Added connection 0. The cache now contains 1 members
*   Trying 23.42.68.108...
* STATE: CONNECT => WAITCONNECT handle 0x80048230; line 1128 (connection #0)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Connected to www.uniqlo.com (23.42.68.108) port 80 (#0)
* STATE: WAITCONNECT => SENDPROTOCONNECT handle 0x80048230; line 1225 (connection #0)
* STATE: SENDPROTOCONNECT => DO handle 0x80048230; line 1243 (connection #0)
> GET / HTTP/1.1
> Host: www.uniqlo.com
> User-Agent: curl/7.43.0
> Accept: */*
>
* STATE: DO => DO_DONE handle 0x80048230; line 1322 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x80048230; line 1449 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x80048230; line 1459 (connection #0)
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 302 Moved Temporarily
* Server AkamaiGHost is not blacklisted
< Server: AkamaiGHost
< Content-Length: 0
< Location: http://www.uniqlo.com/jp/
< Cache-Control: max-age=0
< Expires: Thu, 13 Aug 2015 14:01:37 GMT
< Date: Thu, 13 Aug 2015 14:01:37 GMT
< Connection: keep-alive
<
* STATE: PERFORM => DONE handle 0x80048230; line 1617 (connection #0)
* Curl_done
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host www.uniqlo.com left intact
* Expire cleared


Adding Request Header

$ curl -H "X-Custom-Header: test"  http://xxxxxxx/


Login

curl -c cookie.txt -d "user=user01" -d "pass=password" "http://example.com/login"
curl -b cookie.txt "http://exapmle.com/admin/get_data"


FTP

list directory

curl -u user:pass ftp://192.168.0.10/xxx/

get file

curl -u user:pass ftp://192.168.0.10/xxx/aaa.txt


WebSocket

Port 80

$ curl -v -i -N -H 'Sec-WebSocket-Version: 13' -H "Sec-WebSocket-Key: $(head -c 16 /dev/urandom | base64)" -H "Connection: Upgrade" -H "Upgrade: websocket" http://example.com/test/websocket

Port 443

$ curl -v -i -N -H 'Sec-WebSocket-Version: 13' -H "Sec-WebSocket-Key: $(head -c 16 /dev/urandom | base64)" -H "Connection: Upgrade" -H "Upgrade: websocket" https://example.com/test/websocket
$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: https://www.websocket.org" https://echo.websocket.org


Akamai

# curl -H "Pragma: akamai-x-cache-on, akamai-x-cache-remote-on, akamai-x-check-cacheable, akamai-x-get-cache-key, akamai-x-get-extracted-values, akamai-x-get-nonces, akamai-x-get-ssl-client-session-id, akamai-x-get-true-cache-key, akamai-x-serial-no"  -IXGET https://www.uniqlo.com/
HTTP/1.1 302 Moved Temporarily
Server: AkamaiGHost
Content-Length: 0
Location: http://www.uniqlo.com/jp/
Cache-Control: max-age=0
Expires: Sun, 22 Jan 2017 00:47:23 GMT
Date: Sun, 22 Jan 2017 00:47:23 GMT
X-Cache: TCP_MISS from a104-79-10-205.deploy.akamaitechnologies.com (AkamaiGHost/8.2.0.0.2-18911410) (-)
X-Cache-Key: S/=/1753/27115/30d/orwww.uniqlo.com/
X-True-Cache-Key: /=/orwww.uniqlo.com/
X-Akamai-Session-Info: name=AKA_PM_BASEDIR; value=
X-Akamai-Session-Info: name=AKA_PM_CACHEABLE_OBJECT; value=true
X-Akamai-Session-Info: name=AKA_PM_FWD_URL; value=/
X-Akamai-Session-Info: name=AKA_PM_NETSTORAGE_ROOT; value=
X-Akamai-Session-Info: name=AKA_PM_PREFETCH_ON; value=true
X-Akamai-Session-Info: name=AKA_PM_RUM_ENABLED; value=on
X-Akamai-Session-Info: name=AKA_PM_SR_ENABLED; value=true
X-Akamai-Session-Info: name=AKA_PM_SR_NODE_ID; value=0
X-Akamai-Session-Info: name=AKA_PM_TD_ENABLED; value=true
X-Akamai-Session-Info: name=AKA_PM_TD_MAP_PREFIX; value=ch
X-Akamai-Session-Info: name=FASTTCP_RENO_FALLBACK_DISABLE_OPTOUT; value=on
X-Akamai-Session-Info: name=FEO_ON; value=true
X-Akamai-Session-Info: name=NL_10630_IPBYPASSLIST_NAME; value=IP Bypass List
X-Akamai-Session-Info: name=NL_14478_WAFWPIPBYPASSLIST_NAME; value=WAF_WP_IP Bypass List
X-Akamai-Session-Info: name=NL_19820_RATECONTROLSBYPASS_NAME; value=Rate Controls Bypass
X-Akamai-Session-Info: name=NL_365_AKAMAITOREXITNODES_NAME; value=Tor Akamai Network List
X-Akamai-Session-Info: name=NL_5823_IPBLOCKLIST_NAME; value=IP_Blocklist
X-Akamai-Session-Info: name=NL_7622_GEOBLOCKLIST_NAME; value=Geo_Blocklist
X-Akamai-Session-Info: name=NL_7622_GEOBLOCKLIST_VALUE; value=
X-Akamai-Session-Info: name=OVERRIDE_HTTPS_IE_CACHE_BUST; value=all
X-Akamai-Session-Info: name=RANDOM_SAMPLE; value=false
X-Akamai-Session-Info: name=SQLI_SELECT_STATEMENT_COUNT; value=0
X-Akamai-Session-Info: name=STRICT_BASELINE_V1ARL_CHECKS; value=<<ENCRYPTED>>
X-Akamai-Session-Info: name=TAP_NIM_URL_FOR_REGEX; value=https://www.uniqlo.com/
X-Akamai-Session-Info: name=TCP_OPT_APPLIED; value=medium
X-Akamai-Session-Info: name=WAF_MYSQLI_COUNT; value=0
X-Serial: 1753
Connection: keep-alive
X-Check-Cacheable: NO










Linux Commands#Network




os/linux/command/curl.html.txt · Last modified: 2018/09/10 by admin

Page Tools