File: netcat-middleman.sh

package info (click to toggle)
panoramisk 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 604 kB
  • sloc: python: 1,557; makefile: 133; sh: 28
file content (24 lines) | stat: -rwxr-xr-x 549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

host=localhost
port=5039
if [ "$1" != "" ]; then
    host=$1
    port=5038
fi;

while true
do
    BACKUP_EXT=$(date +%y%m%d%h%m%s)
    if [[ -f outgoing.log ]]; then
        cp outgoing.log outgoing.log.$BACKUP_EXT
    fi
    if [[ -f incoming.log ]]; then
        cp incoming.log incoming.log.$BACKUP_EXT
    fi
    rm pipe
    mkfifo pipe
    echo "Listening on localhost:$port"
    echo "Capture incoming and outgoing traffic from $host:5038"
    nc -l -p $port < pipe | tee outgoing.log | nc $host 5038 | tee pipe incoming.log
done