Member-only story
Curl as a Network Protocol Testing Tool

Curl is commonly known as its capability dealing with HTTP and HTTPS services. But in fact it has a wide range of protocol that are supported. This make it a perfect tool for testing in some of the restricted environment where other tool could not be easily obtained. The same applies to the container environment.
Let’s explore some of theses protocols curl supports.
Telnet with Curl
Open a telnet session with curl using the common format as protocol://hostname:port
For an example, the HTTP service, type in “GET / HTTP/1.0” and enter twice, then we will have the HTTP response.
curl telnet://google.com:80
GET / HTTP/1.0
HTTP/1.0 200 OK
Date: Thu, 13 Apr 2023 08:12:59 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-0UjfoqjKKH08-IJyvrc2KA' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
...
With the telnet, we can send email to a SMTP server on the telnet session. But a better approach is to use the built-in protocol support for SMTP.
Send SMTP Email with Curl
Let’s prepare a email text file, named as email.txt, as below,
From: admin@cloud.apps.io.cpak
To: targetuser@test.com
Subject: Test email
Hi there,
This is just a test emappil.
Now using the following curl command talk to the SMTP server to send the email.
curl -v smtp://sandbox.smtp.mailtrap.io \
--mail-from admin@cloud.apps.io.cpak \
--mail-rcpt targetuser@test.com \
--upload-file email.txt --user username:password
Some of the verbose output is listed as below,
< 220 smtp.mailtrap.io ESMTP ready
> EHLO email.txt
...
> MAIL FROM:<admin@cloud.apps.io.cpak> SIZE=114
< 250 2.1.0 Ok
> RCPT TO:<targetuser@test.com>
< 250 2.1.0 Ok
> DATA
< 354 Go ahead
} [114 bytes data]
* We are completely uploaded and fine
< 250 2.0.0…