'How to pipe a quit/exit to a curl command that is using telnet

For systems that have telnet disabled (most systems in production), curl is often used instead in order to get around this limitation.

How can an exit or quit be piped to a command like telnet that is waiting for user input? I need the ability for the curl with telnet to exit immediately or after 5 seconds, as the output will tell me if communication is blocked or accepted.

(what goes here?) | curl -v telnet://host:port

some-server01:~ # exit | curl -v telnet://host:port

* Rebuilt URL to: telnet://host:port/
* Hostname was NOT found in DNS cache
*   Trying XXX.XXX.XXX.XXX...
* Connected to host (XXX.XXX.XXX.XXX) port (#0)
* RCVD IAC 0

^C


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source