2 # netsmap-to-devinfo - netdisovered then smap'ed IP addresses to MAC IEEE
3 # and custom information
4 # Copyright (C) 2009 Daniel Dickinson
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 MACTODEV=mac-to-devinfo
24 echo "$0: -i interferace -r ip-range [options]"
26 echo "-r ip-range range to probe (CIDR, e.g. 192.168.2.0/24)"
27 echo "-i interface interface to use in scan"
28 echo "-t timeout time to rate for arp responses for device detection"
29 echo "-p port[,port...] command-separated lists of ports to scan for SIP responses"
30 echo "-c repeat_count Number of times to send each request (default 1)"
31 echo "-s sleepreq ms to wait between sending arp requests"
32 echo "-x Assume we're running on an Xcelerator IP"
37 while getopts "r:i:t:p:c:s:xh" param; do
73 if [ "$IPRANGE" = "" ]; then
74 echo "Must specify an ip range"
79 if [ "$INTERFACE" = "" ]; then
80 echo "Must speciy the interface"
85 if [ "$TIMEOUT" = "" ]; then
92 if [ -n "$PORTARG" ]; then
95 if [ -z "$(echo $PORTLIST | grep ',')" ]; then
100 curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
101 while [ "$curport" != "$oldcurport" ]; do
102 PORTS="$curport $PORTS"
103 FIELD=$(($FIELD + 1))
104 oldcurport="$(echo $PORTLIST | cut -f$FIELD -d, )"
105 curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
116 if [ -n "$REPEATCOUNT" ]; then
117 REPEAT="-c $REPEATCOUNT"
120 for line in $(sh -c "netdiscover -t $TIMEOUT -k -m -i $INTERFACE -r $IPRANGE $REPEAT $SLEEPREQ 2>/dev/null" | grep -E '[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?'); do
122 IP=$(echo $line | tr -s \ | cut -f1 -d\ )
123 MAC=$(echo $line | tr -s \ | cut -f2 -d\ )
125 if [ -n "$PORTS" ]; then
126 for port in $PORTS; do
128 if [ "$XIP" = "TRUE" ]; then
131 for sip_device in $(smap -p $port $IP </dev/null | grep -E -v 'host.? scanned' | grep 'SIP enabled' | cut -f1 -d: ); do
132 if [ -x "$(which httping)" ]; then
133 if httping -G -q -o 401,200 -c 2 -h $sip_device; then
134 echo "$sip_device"" | ""$($MACTODEV $XIP_PORT $MAC)"" | ""http://$sip_device/"
138 echo "$sip_device"" | ""$(MACTODEV $XIP_PORT $MAC)"" | "" - "
142 for sip_device in $(smap $IP </dev/null | grep -E -v 'host.? scanned' | grep 'SIP enabled' | cut -f1 -d: ); do
143 if [ -x "$(which httping)" ]; then
144 if httping -G -q -o 401,200 -c 2 -h $sip_device; then
145 echo "$sip_device"" | ""$($MACTODEV $MAC $XIP_PORT)"" | ""http://$sip_device/"
149 echo "$sip_device"" | ""$($MACTODEV $MAC $XIP_PORT)"" | "" - "