moth/packages/octopus/solution.sh

17 lines
372 B
Bash
Raw Normal View History

2010-09-26 21:56:51 -06:00
#! /bin/sh
port=8888
2011-09-21 16:19:00 -06:00
host=${1:-[::1]}
2010-09-26 21:56:51 -06:00
blooper=$(tempfile)
trap "rm $blooper" 0
2011-09-21 16:19:00 -06:00
echo foo | socat -t 0.01 STDIO UDP6:$host:$port | tail -n +5 > $blooper
2010-09-26 21:56:51 -06:00
for i in $(seq 8); do
2011-09-21 16:19:00 -06:00
result=$(socat -t 0.01 STDIO UDP6:$host:$port < $blooper | awk -F': ' '(NF > 1) {print $2; exit;}')
port=$(printf "%d" "0$result")
2011-03-03 20:46:50 -07:00
echo "next port: $port ($result)"
2010-09-26 21:56:51 -06:00
done
2011-09-21 16:19:00 -06:00
echo $result