5bfc13fc6791c0b123d4f4400ab284103cf0ffaf
[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 OUIDIR=/var/cache/mac-to-devinfo
6
7 XIP_SCANS=FALSE
8
9 usage() {
10 echo "Usage: $0 IP-Range [-r ratelimit] [-i interface] [-x] [port,port,...]"
11 }
12 if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ "$3" == "-h" ] || [ -z "$1" ]; then
13 usage
14 exit 1
15 fi
16
17 IPRANGE="$1"
18 shift
19
20 if [ "$1" == "-r" ]; then
21 RATELIMIT="-r $2"
22 if [ -z "$RATELIMIT" ]; then
23 echo "-r without a ratelimit"
24 usage
25 exit 1
26 fi
27 shift
28 shift
29 fi
30
31 if [ "$1" == "-i" ]; then
32 INTERFACE="-i $2"
33 if [ -z "$INTERFACE" ]; then
34 echo "-i without interface"
35 usage
36 exit 1
37 fi
38 shift
39 shift
40 fi
41
42 if [ "$1" == "-x" ]; then
43 XIP_SCANS=TRUE
44 shift
45 fi
46
47 if [ -n "$1" ]; then
48 PORTLIST="$1"
49
50 if [ -z "$(echo $PORTLIST | grep ',')" ]; then
51 PORTS="$PORTLIST"
52 else
53 FIELD=1
54 oldcurport=""
55 curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
56 while [ "$curport" != "$oldcurport" ]; do
57 PORTS="$curport $PORTS"
58 FIELD=$(($FIELD + 1))
59 oldcurport="$(echo $PORTLIST | cut -f$FIELD -d, )"
60 curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
61 done
62 fi
63 fi
64
65 prep-devinfo
66
67 if [ -z "$PORTS" ]; then
68 PORTS=5060
69 fi
70
71 for port in $PORTS; do
72
73 if [ "$XIP_SCANS" == "TRUE" ]; then
74 XIP_PORT="-x $port"
75 fi
76 for sip_device in $($SMAP $RATELIMIT -p $port $IPRANGE | grep -E -v 'host.? scanned' | grep 'SIP enabled' | cut -f1 -d: ); do
77 if [ -x "$(which httping)" ]; then
78 if httping -G -q -o 401,200 -c 2 -h $sip_device; then
79 echo "$sip_device"" | ""$($IPTODEV $INTERFACE $XIP_PORT $sip_device)"" | ""http://$sip_device/"
80 continue
81 fi
82 fi
83 echo "$sip_device"" | ""$(IPTODEV $XIP_PORT $sip_device)"" | "" - "
84 done
85 done
86