netchatte is a netcat based terminal chat program, inspired by 'unnamed project' and made during the first tangible clouds worksession 18th → 21st May 2022 in Brussels (https://tangible-cloud.be/)
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
152 lines
2.8 KiB
152 lines
2.8 KiB
2 years ago
|
#!/usr/bin/env bash
|
||
|
# usage: chmod all .sh files, be on the same network and run ./netchatte.sh
|
||
|
# todo:
|
||
|
# nicknames
|
||
|
# filesharing
|
||
|
|
||
|
|
||
|
# copyleft, netchatte is a netcat based terminal chat
|
||
|
# program, inspired by 'unnamed project' and made during the first tangible clouds worksession
|
||
|
# 18th → 21st May 2022 in Brussels (https://tangible-cloud.be/)
|
||
|
#
|
||
|
|
||
|
#init
|
||
|
unset ALLCLIENTS
|
||
|
unset TEMPCLIENTS
|
||
|
unset IP
|
||
|
#define listen port
|
||
|
#define server port....
|
||
|
|
||
|
|
||
|
#functions
|
||
|
mainMenu ()
|
||
|
{
|
||
|
printf "\n ===== MAIN MENU ===== \n"
|
||
|
printf "\n"
|
||
|
echo "Hello, pick an option:"
|
||
|
printf "\n"
|
||
|
select mainMenu in "Who is online?" "Chat"
|
||
|
do
|
||
|
#echo $mainMenu
|
||
|
case $mainMenu in
|
||
|
"Who is online?")
|
||
|
scan
|
||
|
;;
|
||
|
Chat)
|
||
|
chat
|
||
|
;;
|
||
|
# if [ '1' = "$REPLY" ]; then
|
||
|
# scan
|
||
|
# fi
|
||
|
|
||
|
#echo "Selected number: $REPLY"
|
||
|
esac
|
||
|
done
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
scan ()
|
||
|
{
|
||
|
printf "\n"
|
||
|
sleep 0
|
||
|
echo "Searching for friends..."
|
||
|
sleep 2
|
||
|
printf "\n"
|
||
|
#scanOutput=$(arp -a | awk -F'[()]' '{print $2}' | head -1)
|
||
|
|
||
|
# find all machines on the network
|
||
|
while IFS= read -r LINE; do
|
||
|
ALLCLIENTS+=("${LINE}")
|
||
|
#REALCLIENTS=( $(nc -zv -G 1 ${LINE} 1234 2>&1 | grep --line-buffered succeeded | awk '{print $3}') ) #see if port of client is open
|
||
|
done < <(arp -a -x | awk '{print $1}' | tail -n +2)
|
||
|
|
||
|
|
||
|
# for each machine, see if we can connect to it
|
||
|
for i in "${ALLCLIENTS[@]}"
|
||
|
do
|
||
|
:
|
||
|
TEMPCLIENTS=( $(nc -zv -G 1 $i 1234 2>&1 | grep --line-buffered succeeded | awk '{print $3}' ))
|
||
|
|
||
|
|
||
|
|
||
|
if [ ${#TEMPCLIENTS[@]} -eq 0 ]; then
|
||
|
echo "."
|
||
|
#printf "\n"
|
||
|
|
||
|
else
|
||
|
#echo "Found the following clients:"
|
||
|
#echo "$i"
|
||
|
REALCLIENTS+=("${i}")
|
||
|
fi
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
done
|
||
|
|
||
|
|
||
|
# Iterate over an array to create select menu
|
||
|
if [ ${#REALCLIENTS[@]} -eq 0 ]; then
|
||
|
echo "No clients found :("
|
||
|
printf "\n"
|
||
|
else
|
||
|
echo "Found a friend!:"
|
||
|
printf "\n"
|
||
|
#echo "${#REALCLIENTS[@]}"
|
||
|
fi
|
||
|
select IP in "${REALCLIENTS[@]}" "Back to main menu"; do
|
||
|
case ${IP} in
|
||
|
1*) #limitation: ip must start with a 1....
|
||
|
echo "Client ${IP} selected"
|
||
|
IP+=("${IP}")
|
||
|
# Further processing
|
||
|
|
||
|
;;
|
||
|
"Back to main menu")
|
||
|
printf "\n"
|
||
|
mainMenu
|
||
|
#break
|
||
|
;;
|
||
|
*)
|
||
|
echo "Not available"
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
chat ()
|
||
|
{
|
||
|
screen -c screenrc #launch split screen session with tx.sh and rx.sh
|
||
|
}
|
||
|
|
||
|
#Main 'loop'
|
||
|
echo "booting...netchatte"
|
||
|
sleep 1
|
||
|
printf "\n"
|
||
|
|
||
|
cat << "EOF"
|
||
|
,-. _,---._ __ / \
|
||
|
/ ) .-' `./ / \
|
||
|
( ( ,' `/ /|
|
||
|
\ `-" \'\ / |
|
||
|
`. , \ \ / |
|
||
|
/`. ,'-`----Y |
|
||
|
( ; | '
|
||
|
| ,-. ,-' | /
|
||
|
| | ( | hjw | /
|
||
|
) | \ `.___________|/
|
||
|
`--' `--'
|
||
|
EOF
|
||
|
|
||
|
|
||
|
killall nc &> /dev/null # clean up (maybe add killall screen..haha dirty)
|
||
|
mainMenu #start main function
|
||
|
|
||
|
|
||
|
|
||
|
|