Skip to main content
Explanation moved from comment to answer
Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

You need to direct both stderr and stdout into the file:

nc -vv -z localhost 1-80 > file.txt 2>&1

Running the command against just one port (80) didn't generate any messages to stderr, so writing stdout to the file was sufficient to capture everything. However, with a range of ports (1-80) we definitely get output written to stderr, so we need to capture that in addition to the redirect that captures stdout.

You need to direct both stderr and stdout into the file:

nc -vv -z localhost 1-80 > file.txt 2>&1

You need to direct both stderr and stdout into the file:

nc -vv -z localhost 1-80 > file.txt 2>&1

Running the command against just one port (80) didn't generate any messages to stderr, so writing stdout to the file was sufficient to capture everything. However, with a range of ports (1-80) we definitely get output written to stderr, so we need to capture that in addition to the redirect that captures stdout.

Source Link
Chris Davies
  • 128.2k
  • 16
  • 179
  • 324

You need to direct both stderr and stdout into the file:

nc -vv -z localhost 1-80 > file.txt 2>&1