add packages_10.03.2 in preparation for the 10.03.2 interim release
[10.03/packages.git] / net / mac-to-devinfo / files / netdiscover-to-devinfo
1 #!/bin/sh
2 #    netdiscover-to-devinfo - netdiscover to MAC IEEE and custom information
3 #    Copyright (C) 2009  Daniel Dickinson
4
5 #    This program is free software; you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation; either version 2 of the License, or
8 #    (at your option) any later version.
9
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14
15 #    You should have received a copy of the GNU General Public License along
16 #    with this program; if not, write to the Free Software Foundation, Inc.,
17 #    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 MACTODEV=mac-to-devinfo
20
21 if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
22     echo "Usage: netdiscover-to-devinfo IP-range Interface Timeout [-r repeats] [-s sleep_between_arp_requests]"
23     exit 1
24 fi
25
26 prep-devinfo
27 IFS='
28 '
29
30 IPRANGE=$1
31 IFACE=$2
32 TIMEOUT=$3
33
34 shift 3
35
36 while getopts "r:s:h" param; do
37     case "$param" in
38         h)
39             usage
40             exit 1
41             ;;
42         r)
43             REPEATS=" -c $OPTARG"
44             ;;
45         s)
46             SLEEPREQ="-s $OPTARG"
47             ;;
48         ?|*)
49             usage
50             exit 1
51             break
52             ;;
53
54     esac
55 done
56
57
58 for line in $(sh -c "netdiscover -t $TIMEOUT-k -m -i $IFACE -r $IPRANGE $REPEATS $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
59     unset IFS
60     IP=$(echo $line | tr -s \  |  cut -f1 -d\  )
61     MAC=$(echo $line | tr -s \  |  cut -f2 -d\  )
62     echo "$IP"" | ""$($MACTODEV $MAC)"
63     IFS='
64 '
65 done
66
67 unset IFS