Browse Source

added scripts and readme

master
then 3 months ago
parent
commit
9e6485da41
  1. 26
      README.md
  2. 151
      netchatte.sh
  3. 8
      rx.sh
  4. 6
      screenrc
  5. 131
      tx.sh

26
README.md

@ -1,3 +1,25 @@
# netchatte
```
,-. _,---._ __ / \
/ ) .-' `./ / \
( ( ,' `/ /|
\ `-" \'\ / |
`. , \ \ / |
/`. ,'-`----Y |
( ; | '
| ,-. ,-' | /
| | ( | hjw | /
) | \ `.___________|/
`--' `--'`
```
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/)
# usage: chmod all .sh files, be on the same network and run ./netchatte.sh
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/)

151
netchatte.sh

@ -0,0 +1,151 @@
#!/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

8
rx.sh

@ -0,0 +1,8 @@
#!/usr/bin/env bash
LOCALIP=$(ipconfig getifaddr en0)
while true
do
nc -lk ${LOCALIP} 1234 #this shoul be remote ip
done

6
screenrc

@ -0,0 +1,6 @@
bindkey ^D quit
screen -t you bash ./tx.sh
split
focus down
screen -t friend bash ./rx.sh
focus up

131
tx.sh

@ -0,0 +1,131 @@
#!/usr/bin/env bash
LOCALIP=$(ipconfig getifaddr en0)
#setup
foundfriend=0
#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
}
while : ; do
unset ALLCLIENTS
unset TEMPCLIENTS
unset REALCLIENTS
printf "\n"
echo "Waiting 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 -ne "."
#printf "\n"
else
#echo "Found the following clients:"
#echo "$i"
REALCLIENTS+=("${i}")
fi
done
#remove own IP from array (breaks the 'no clients found' script below...somehow)
#echo ${LOCALIP}
delete=${LOCALIP}
#echo "localhost:.."
echo "${REALCLIENTS[@]/$delete}"
if [ ${#REALCLIENTS[@]} -eq 0 ]; then
echo "No clients found :("
printf "\n"
else
if [ ${#REALCLIENTS[@]} -ne 0 ] && [ "${REALCLIENTS}" != "${LOCALIP}" ] ; then #remove your own ip, make a list you can choose from here, and add nickname
echo "Found a friend!:"
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}")
printf "\n"
echo "${IP}"
printf "\n"
printf "Connecting..."
printf "\n"
sleep 1
printf "Connected! Type your message and press [enter], CTRL+D to quit:"
printf "\n\n"
#construct a string to be send to nc...todo
# read -p 'Please choose a nickname: ' nickname
# echo -ne "$nickname" # how to prepend a nickname and send it
# https://superuser.com/questions/261900/how-can-i-pipe-commands-to-a-netcat-that-will-stay-alive
nc ${IP} 1234
;;
"Back to main menu")
printf "\n"
mainMenu
#break
;;
*)
echo "Not available"
;;
esac
done
break
fi
sleep 5
fi
done
Loading…
Cancel
Save