[package] add mac-to-devinfo (#5373)
[openwrt/svn-archive/archive.git] / net / mac-to-devinfo / files / smap-to-devinfo
1 #!/bin/sh
2
3 IPTODEV=ip-to-devinfo
4 SMAP=smap
5
6 if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ -z "$1" ]; then
7 echo "Usage: $0 IP-Range [port,port,...]"
8 fi
9
10 if [ -n "$2" ]; then
11 FIELD=1
12 curport="$(echo $2 | cut -f$FIELD -d, )"
13 while [ "$curport" != "" ]; do
14 PORTS="$curport $PORTS"
15 FIELD=$(($FIELD + 1))
16 curport="$(echo $2 | cut -f$FIELD -d, )"
17 done
18 fi
19
20 prep-devinfo
21
22 if [ -z "$PORTS" ]; then
23 PORTS=5060
24 fi
25
26 for port in $PORTS; do
27 for sip_device in $($SMAP -p $port $1 | grep -E -v 'host.? scanned' | grep 'SIP enabled' | cut -f1 -d: ); do
28 if [ -x "$(which httping)" ]; then
29 if httping -G -q -o 401,200 -c 2 -h $sip_device; then
30 echo "$sip_device"" | ""$($IPTODEV $sip_device)"" | ""http://$sip_device/"
31 continue
32 fi
33 fi
34 echo "$sip_device"" | ""$(IPTODEV $sip_device)"" | "" - "
35 done
36 done
37