I almost forget this command, but recently I used it as a TCP client to test Envoy TCP proxy. nc
can also be a TCP server that listening on port and waiting for connection.
Install
1 | # install nc (netcat) |
Note that some nc version may support different features and options, please read man first!!
Usage Example
Test networking between 2 machines is good:
1 | # on one machine, set up listener |
I used to set up a UDP client to test logstash input UDP plugin and pipeline.
Proxy
Connection via proxy, see man nc
:
1 | # https connect |
Port Scan
Port scanning to know which ports are open and running services on target machine:
1 | # -v: verbose |
Transfer
Data transfer, also see man nc
1 | # content will be put to filename.out |
For folder transfer:
1 | # note there is a - after tar command, used as input |
Other ways to transfer files: scp, sftp, python http server.
Server Client
Client/Server model, a chat server, can talk in either way:
TCP server and client
1 | # server |
UDP server and client
1 | # server |
Actually you can use it in script:
1 |
|
Backdoor
Execute command on remote via backdoor opened by nc
, see nc’s manual
1 | # server side, mk a named pipe |