62 lines
904 B
Bash
Executable File
62 lines
904 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
ip="${1}"
|
|
port="${2}"
|
|
[ -z "${ip}" ] && print_usage 'No IP given.'
|
|
[ -z "${port}" ] && print_usage 'No port given.'
|
|
[ -z "${3}" ] || print_usage 'Too many arguments.'
|
|
get_termsize() {
|
|
echo "`expr $(stty -a < $(tty) | grep -Po '(?<=rows )\d+') - 1`"
|
|
}
|
|
print_usage() {
|
|
echo "${1}"
|
|
echo "${0} <IP> <PORT>"
|
|
exit
|
|
}
|
|
|
|
send_message() {
|
|
exec 3<> "/dev/tcp/${ip}/${port}"
|
|
echo "${1}" >&3
|
|
exec 3>&-
|
|
}
|
|
|
|
get_message() {
|
|
exec 3<> "/dev/tcp/${ip}/${port}"
|
|
echo "${1}" >&3
|
|
timeout 1s cat <&3 || true
|
|
exec 3>&-
|
|
}
|
|
|
|
while :; do
|
|
read cmd
|
|
case "${cmd}" in
|
|
i)
|
|
b=""
|
|
while :; do
|
|
read c
|
|
[[ "${c}" != "." ]] || break
|
|
if [ -z ${b} ]; then
|
|
b="${c}"
|
|
else
|
|
b="${b}"$'\n'"${c}"
|
|
fi
|
|
done
|
|
send_message 0"${b}"
|
|
;;
|
|
I)
|
|
read a
|
|
send_message 0"${a}"
|
|
;;
|
|
p)
|
|
send_message 1
|
|
get_message 2
|
|
;;
|
|
q)
|
|
exit
|
|
;;
|
|
*)
|
|
echo ?
|
|
;;
|
|
esac
|
|
done
|