summaryrefslogtreecommitdiffstats
path: root/scripts/offer_handshake.sh
blob: 1564a76d2fda6905c5457dd7baa57721af14d170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash

# here configure the file with the list of IP or hostnames, one per line
LISTFILE=/root/list

if [ -z $1 ]; then
        echo "usage: $0 network_interface"
        echo "example: $0 eth0"
        exit 1
fi
IFACE="$1"

IP="`ifconfig $IFACE | grep 'inet addr'| awk '{print $2}'|cut -f2 -d:`"


NC="/opt/ivysync/bin/netcat"
# check if it is openbsd netcat
NC_ver="`$NC -h 2>&1|head -n 1 | awk '{print $1}'`"
if [ "$NC_ver" = "OpenBSD" ]; then
	echo "using OpenBSD version of netcat"
	NC="$NC -q 0"
elif [ "$NC_ver" = "GNU" ]; then
	echo "using GNU version of netcat"
	NC="$NC -c"
else
	echo "error: your version of netcat is not compatible"
	echo "please install an OpenBSD or GNU netcat implementation"
	echo "found on this system: `netcat -h 2>&1|head -n1`"
	exit 1
fi



ready=false

for i in `cat $LISTFILE`; do
	rm -f /tmp/handshake.$i.ok
	echo -n "handshaking $i"

	# background listener
	(answer=`echo | $NC -u -l -p 3331`;
	 echo $answer > /tmp/handshake.$i.ok) &

	while ! [ -r /tmp/handshake.$i.ok ]; do
		sleep 1
		udpbroadcast $i 3332 $IP 1>&2 > /dev/null
		echo -n "."
	done	
	echo -n " answer: `cat /tmp/handshake.$i.ok`"
	rm /tmp/handshake.$i.ok
	echo
done