tldr/pages/common/nc.md

37 lines
832 B
Markdown
Raw Normal View History

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