Bash – Write output from netcat to a file

bashnetcat

I'm currently trying to write a scan port result to a text file

Here is the command I tried to use:

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

This doesn't work (that is, the error messages from nc don't end up in file.txt), but when I type: nc -vv -z localhost 80 > file.txt
It works.

I already know that there is an output but I can't write that in a file.

Best Answer

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

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