Debian Codegraph @

scripts/tcp-proxy.sh

raw
1 #!/bin/sh -e
2 # Display TCP packets
3 # code from:
4 # https://notes.tweakblogs.net/blog/7955/using-netcat-to-build-a-simple-tcp-proxy-in-linux.html
5
6 if [ $# != 3 ]
7 then
8 echo "usage: $0 <src-port> <dst-host> <dst-port>"
9 exit 0
10 fi
11
12 TMP=`mktemp -d`
13 BACK=$TMP/pipe.back
14 SENT=$TMP/pipe.sent
15 RCVD=$TMP/pipe.rcvd
16 trap 'rm -rf "$TMP"' EXIT
17 mkfifo -m 0600 "$BACK" "$SENT" "$RCVD"
18 sed 's/^/ => /' <"$SENT" &
19 sed 's/^/<= /' <"$RCVD" &
20 nc -l 127.0.0.1 "$1" <"$BACK" | tee "$SENT" | nc "$2" "$3" | tee "$RCVD" >"$BACK"