2014-03-03 21:22:40 +11:00
|
|
|
# nc
|
|
|
|
|
2019-02-16 17:15:04 +00:00
|
|
|
> Netcat is a versatile utility for working with TCP or UDP data.
|
2023-04-12 03:16:15 +09:00
|
|
|
> More information: <https://manned.org/man/nc.1>.
|
2014-03-03 21:22:40 +11:00
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
- Establish a TCP connection:
|
2014-03-03 21:22:40 +11:00
|
|
|
|
|
|
|
`nc {{ip_address}} {{port}}`
|
|
|
|
|
2016-01-07 18:31:27 +01:00
|
|
|
- Set a timeout:
|
2014-03-03 21:22:40 +11:00
|
|
|
|
|
|
|
`nc -w {{timeout_in_seconds}} {{ipaddress}} {{port}}`
|
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
- Scan the open TCP ports of a specified host:
|
2014-03-08 10:37:44 +08:00
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
`nc -v -z {{ip_address}} {{port}}`
|
|
|
|
|
|
|
|
- Listen on a specified TCP port and print any data received:
|
2014-03-08 10:37:44 +08:00
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
`nc -l {{port}}`
|
2014-03-08 10:37:44 +08:00
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
- Keep the server up after the client detaches:
|
2016-06-13 11:54:36 +08:00
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
`nc -k -l {{port}}`
|
2016-06-13 11:54:36 +08:00
|
|
|
|
2023-04-12 03:16:15 +09:00
|
|
|
- Listen on a specified UDP port and print connection details and any data received:
|
|
|
|
|
|
|
|
`nc -u -l {{port}}`
|
2016-06-13 11:54:36 +08:00
|
|
|
|
2019-02-16 17:15:04 +00:00
|
|
|
- Act as proxy and forward data from a local TCP port to the given remote host:
|
2016-06-13 11:54:36 +08:00
|
|
|
|
2019-02-16 17:15:04 +00:00
|
|
|
`nc -l {{local_port}} | nc {{hostname}} {{remote_port}}`
|
2023-04-12 03:16:15 +09:00
|
|
|
|
|
|
|
- Send a HTTP request:
|
|
|
|
|
|
|
|
`echo -e "GET / HTTP/1.1\nHost: {{hostname}}\n\n" | nc {{hostname}} 80`
|