2 # ip-to-devinfo - IP (through arping or ping and arp cache) to MAC IEEE and
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.
21 MACTODEV
=mac-to-devinfo
24 echo "Usage: $0 [-i interface] [-x port] IP-address"
27 if [ "$1" == "-i" ]; then
29 if [ -z "$INTERFACE" ]; then
30 echo "-i without interface"
38 if [ "$1" == "-x" ]; then
40 if [ -z "$PORT" ]; then
41 echo "-x without the port"
53 echo "Must specify IP address"
59 if [ ! -x "$(which $ARP)" ]; then
71 if [ -z "$INTERFACE" ]; then
72 ping -q -c 2 $IP >/dev
/null
73 MAC
=$
(do_arp|
grep "$IP "|
tr -s \ | cut
-f$ARPMACFIELD -d\
)
75 MAC
=$
(arping
-f -c 5 -I $INTERFACE $IP |
grep 'Unicast reply from' | cut
-f2 -d \
[ | cut
-f1 -d\
])