Connect to a TCP service and read its banner with netcat
Build a paste-ready command, then review its compatibility and effects before running it.
printf '\n' | nc -v -w 5 <host> <port>Complete required fields to copy the generated command.
Compatibility
Linux + macOSVerified for Linux, macOS using posix, bash, zsh syntax.
Operational knowledgereview due 2027-01-19
Requirementsprintfprintf must be installed and available on PATH.Network accessThe target must be reachable from the current environment.
Version supportprintf Current supported releasesVerified for linux, macos using posix, bash, zsh syntax; consult compatibility notes for platform-specific differences.
Expected signalsConnection to mail.example.com 25 port [tcp/smtp] succeeded!Representative successful output; values vary with the selected target and system state.
Known errorsprintf: command not foundprintf is missing or is not available on PATH.
Verifyprintf '\n' | nc -v -w 5 {{host}} {{port}}The output matches the expected target and exits without an error.Rollback noteNot required: this command is read-only and does not change system state.
Command breakdown
01printfCommandRuns the printf stage of this one-liner.
02'\n'ArgumentPasses '\n' to printf.
03|PipelinePasses the output on the left to the command on the right.
04ncCommandRuns the nc stage of this one-liner.
05-vOptionPrints connection details while netcat connects to the service.
06-wOptionStops connecting or waiting for network input after the given timeout.
08<host>ParameterA value supplied in the Fill parameters section.
09<port>ParameterA value supplied in the Fill parameters section.
Example input
printf '\n' | nc -v -w 5 mail.example.com 25
Example output
Connection to mail.example.com 25 port [tcp/smtp] succeeded!
220 mail.example.com ESMTP Postfix
Illustrative output — exact values vary by system and data.
Official sources
Related commands