Per Stenebo
2018-03-18 09:06:31
2023-02-13 14:28:56
netcat and similar tools
| Wikipedia page about netcat |
netcat.traditional
The classic netcat, written by Hobbit. Installed on a default Debian Stretch and Buster.
| Ubuntu man page | stackexchange tunnel |
Install, on debian-like systems:
sudo apt install netcat-traditional
Check if port 80 is open: nc -zv google.com 80
Connection to google.com (142.251.143.78) 80 port [tcp/http] succeeded!
Relay server; redirect incoming (external) request on port 5060 to local port 8022:
nc.traditional -l -p 5060 -c "nc.traditional 127.0.0.1 8022"
nc - netcat (OpenBSD)
netcat-openbsd - the OpenBSD rewrite of netcat, including support for IPv6, proxies, and Unix sockets. Installed in a default Ubuntu 16.04.
| Generic man page | Ubuntu man page | Debian man page | Ubuntu 16.04 man page |
Install: sudo apt install netcat-openbsd
Check (installed) package: apt-cache policy netcat-openbsd
Check if a port is open: nc -z -w 3 myhost 10026 && echo open || echo closed
ncat (by nmap)
ncat - the nmap rewrite of netcat
| nmap ncat page | Ubuntu man page | nmap ncat guide | 10 useful ncat (nc) Command Examples |
Install full nmap package with ncat, or just ncat, on debian-like systems:
sudo apt install nmap | sudo apt install ncat
Relay server; redirect incoming (external) request on port 5060 to local port 8022:
ncat -l -p 5060 -c "ncat 127.0.0.1 8022"
Proxy requests on port 8080 to 192.168.1.200:80:
mkfifo 2way
ncat -l 8080 0<2way | ncat 192.168.1.200 80 1>2way
socat
| socat | Ubuntu man page | Getting started |
Install socat:
sudo apt install socat
Test if a port is open: socat - TCP:myhost:10026 && echo open || echo closed
Create two connected serial ports:
socat -d -d pty,raw,echo=0 pty,raw,echo=0
2018/02/04 11:15:45 socat[10376] N PTY is /dev/pts/21 2018/02/04 11:15:45 socat[10376] N PTY is /dev/pts/22 2018/02/04 11:15:45 socat[10376] N starting data transfer loop with FDs [5,5] and [7,7]
Source: simple way to create a tunnel from one local port to another
Relay server; redirect incoming (external) request on port 5060 to local port 8022:
socat tcp-listen:5060,reuseaddr,fork tcp:localhost:8022