EMZETT.
Login

netcat and socat

In short: netcat (nc) and socat are command-line tools that open or accept raw network connections. They are called the “Swiss army knife” of networking.

In more detail: They connect standard input and output to a TCP, UDP or Unix-socket connection. That lets you test services, transfer data and forward connections.

In Depth

  • Check a port: nc -zv server 443 shows whether a TCP port is reachable.
  • Listen: nc -l 9000 waits for a connection and prints what arrives. Handy for seeing what a program sends.
  • Send a file: Receiver nc -l 9000 > file, sender nc receiver 9000 < file.
  • Protocols by hand: printf 'GET / HTTP/1.0\r\n\r\n' | nc example.com 80.
  • socat: More powerful: connects any two endpoints (file, pipe, TLS, serial port), such as socat TCP-LISTEN:8080,fork TCP:internal:80 as a simple forwarder or socat - OPENSSL:host:443.
  • Caution: Unencrypted and without login. Open listeners in foreign networks are risky. See sockets.

See also: SSH tunnels and port forwarding