Created
January 22, 2021 00:48
-
-
Save brbsix/001520654133442b8bb309ecb29f339f to your computer and use it in GitHub Desktop.
send_or_receive.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Send or receive data to/from another device on the network. | |
PROGRAM=${0##*/} | |
LOCAL_IP=192.168.1.100 | |
PORT=6666 | |
PASSWORD=topsecret | |
if [[ $# -eq 0 ]]; then | |
socat "TCP-L:$PORT" - | openssl enc -d -a -aes-256-cbc -iter 100000 -pass pass:$PASSWORD | |
elif [[ $# -eq 1 && $1 =~ ^(-c|--clipboard)$ ]]; then | |
if hash termux-clipboard-set &>/dev/null; then | |
CLIPBOARD=termux-clipboard-set | |
elif hash xclip &>/dev/null; then | |
CLIPBOARD='xclip -sel c' | |
elif hash xsel &>/dev/null; then | |
CLIPBOARD='xsel -b' | |
else | |
echo 'ERROR: no clipboard application available' >&2 | |
exit 1 | |
fi | |
socat "TCP-L:$PORT" "SYSTEM:'openssl enc -d -a -aes-256-cbc -iter 100000 -pass pass:$PASSWORD | $CLIPBOARD'" | |
elif [[ $# -eq 2 && $1 =~ ^(-s|-send)$ ]]; then | |
openssl enc -a -aes-256-cbc -iter 100000 -pass pass:k5JKfpbz3032WHis | socat - "TCP:$2:$PORT" | |
else | |
on=$'\033[1m' | |
off=$'\033[0m' | |
cat <<EOF | |
Usage: $PROGRAM [[-c] | -s DEST] | |
Send or receive data to/from another device on the network. | |
-c, --clipboard store received text on the clipboard | |
-s, --send send data to another device | |
${on}RECEIVING DATA:${off} | |
If run without any options, the program will wait to | |
receive data from the network then print it to stdout. | |
In order to receive data on this device, the other device | |
may wish to run a command such as the following: | |
echo data | socat - TCP:$LOCAL_IP:$PORT | |
${on}SENDING DATA:${off} | |
In order to send data to another device, you must pipe it | |
into the standard input of this program. | |
The destination device may wish to use this program to to | |
receive data or it can run a command such as the following: | |
socat TCP-L:$PORT STDOUT | |
EOF | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment