Like any proper pipeline utility, Ncat reads from
and writes to
so you can redirect I/O to or from any program or file. The only
exception is when Ncat is run with the
--sh-exec options, in which case it communicates with
the subprocess instead. Nothing in the streams is added, removed, or
altered, unless you specifically ask for it with an option such as
(CRLF processing) or
(Telnet negotiation). If Ncat prints any diagnostic messages, they are
so as not to interfere with the data stream. By default Ncat does not
print any such messages, but you can enable them with the
-v more than once for even more output.
option or its alias
to record a transcript of everything sent and received to a file:
ncat -C --output smtp-debug.log mail.example.com 25
The log contains everything sent and received without differentiation.
Sometimes a hex dump is more useful than a plain text log; for that
Let's see what happens if we accidentally speak SMTP to an SSH server:
ncat -C --hex-dump ssh-hex.log scanme.nmap.org 22
--hex-dump log file for this session:
 53 53 48 2D 32 2E 30 2D 4F 70 65 6E 53 53 48 5F SSH-2.0- OpenSSH_
 34 2E 33 0A 4.3.
 48 45 4C 4F 20 65 78 61 6D 70 6C 65 2E 63 6F 6D HELO exa mple.com
 0D 0A ..
 50 72 6F 74 6F 63 6F 6C 20 6D 69 73 6D 61 74 63 Protocol mismatc
 68 2E 0A h..
Each transmission is dumped separately. There is a break and the
counter at the left starts over each time there is a new send.