CURL command examples

CURL is a command line tool used to transfer and retrieve data in web. Let’s have a look at few of the useful options while debugging web issues.

Basic syntax $CURL <Options> <hostname or ip-address>

Options are optional. Hostname and IP-address can be interchanged depends upon the options we are selecting.

  1. First example is to use basic one: $curl http://www.google.com
    This will give you page output.
  2. If you want to see the request and response header, use option “-v” for verbose

if we will use “-v” option with https, we can also see SSL handshake negotiation as below:

This is also helpful in debugging if CURL command fails.

3. If you are interested to see, only response header then use “head” option

4.  If we want to use debug SSL website but want to ignore any warning, we can use “ignore” option

$CURL –ignore https://www.google.com

but if we want to negotiate through any specific SSL or TLS version, we can mention the version in the CURL option.

$CURL -tlsv1 https://www.google.com

We can use different SSL versions like sslv3, sslv2 same way.

5. To authenticate /login to a website, “-u” option is used

$CURL -u administrator http://domain.com/login.php

It should prompt for password

6. In order to inject headers into the packet, we can use

curl -u user:password -O ftp://ftpurl/style.css

7. In order to inject http directives in request header, we can use different options:

Modify user-agent: curl -A ‘Mozilla/3.0 (Win95; I)’ http://www.google.com/

Same way, we can modify content-length and also add other directives

8. limit rate: If we want to restrict downloading bandwidth, we can use:
$curl –limit-rate 100k -O https://google.com

9. Use proxy with curl: If we want to login to the destination server by hiding our source IP and login through proxy server, we can use below option:
$curl -x http://proxy.packetflows.com –proxy-user user:password -L http://domain.com/login.php

10. Pause and download with CURL command: Similar to download managers, we can pause and later on resume downloading of file using CURL.
For pause:
$Curl -O http://domain.file.com/assignment.zip

To resume:
$curl -C http://domain.file.com/assignment.zip

Leave a Reply

Your email address will not be published. Required fields are marked *