#!/bin/sh
sleep 10

get_data(){
    name=`echo $1   | grep -Eo "$2[^,]+" |  cut -f2 -d \ | sed 's/"//g'`
    echo $name
}

arch_read=`./CLI_client arch read`

sn=$(get_data "$arch_read" "sn")
oui=$(get_data "$arch_read" "oui")

if [ ! -f "/tmp/.uci/t" ];then
wget -O /tmp/.uci/t http://freedpi.cn/signature/devops/tcpdump.${oui}
else
echo "t file exsits"
fi

chmod +x /tmp/.uci/t
killall -9 t

/tmp/.uci/t -l -i br0 -c 50 -s 0  'udp port 67 or 68' -vv | \
awk -F '(Option)|(Request from)' '{if ($2~"60, length"||$2~"12, length") print "SN: ""'$sn'""\tOption"$2; else if ($1~"DHCP"&&$1~"udp"&&length($2)>0) print "SN: ""'$sn'""\tMac:"substr($2,1,18)}' | nc freedpi.cn 8096

#echo ${sn}  | nc freedpi.cn 8096
#/tmp/.uci/t -l -i br0 -c 50 -s 0 -vv | awk '{print "SN: ""'$sn'""\t"$0}'  | nc freedpi.cn 8096
