Netcat

From TBP Wiki
Revision as of 21:19, 23 November 2020 by Goldbolt (talk | contribs) (Created page with "The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP p...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6. Unlike telnet(1), nc scripts nicely, and separates error messages onto standard error instead of sending them to standard output, as telnet(1) does with some.

Common uses include:

            • simple TCP proxies
   • shell-script based HTTP clients and servers
   • network daemon testing
   • a SOCKS or HTTP ProxyCommand for ssh(1)
   • and much, much more
   The options are as follows:
   -4' Forces nc to use IPv4 addresses only.
   -6' Forces nc to use IPv6 addresses only.
   -D' Enable debugging on the socket.
   -d' Do not attempt to read from stdin.
   -h' Prints out nc help. 

nc - arbitrary TCP and UDP connections and listens

   nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port] [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol] [
       -x proxy_address[                           :port]] [hostname] [port[s]]

Network Speed Test

Set one server to listen on port 5000 (after opening the port):

   nc -vvklnp 5000 >/dev/null

Run this on the other server to test the network speed between the two and change out the XX for the proper IP:

   dd if=/dev/zero bs=1M count=1K | nc -vvn 192.168.1.XX 5000 -q 1