[package] add mac-to-devinfo (#5373)

git-svn-id: svn://svn.openwrt.org/openwrt/packages@16712 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
florian 2009-07-06 11:38:01 +00:00
parent b387ad1fdf
commit 1ecb72b961
9 changed files with 492 additions and 0 deletions

View File

@ -0,0 +1,87 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=mac-to-devinfo
PKG_VERSION:=1.0.0
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/mac-to-devinfo
SECTION:=net
CATEGORY:=Network
TITLE:=MAC Address to Device Information
endef
define Package/mac-to-devinfo/description
Scripts to take a mac address (or ip if the ip is in the arp cache)
and translate it into device information (mostly OUI owner, from the
IEEE data files, but more information may be available for specific
devices/vendors).
endef
define Package/smap-to-devinfo
SECTION:=net
CATEGORY:=Network
DEPENDS:=mac-to-devinfo +smap +httping
TITLE:=SIP Device Information from Scan
endef
define Package/smap-to-devinfo/description
A script to use smap to discover all SIP devices on the networks
(provided ICMP and SIP are allowed to the network from the host) and
translate (through the ip then mac) into the device information.
endef
define Package/netdiscover-to-devinfo
SECTION:=net
CATEGORY:=Network
DEPENDS:=mac-to-devinfo +netdiscover
TITLE:=Device Information from Scan for MAC addresses
endef
define Package/netdiscover-to-devinfo/description
A script to use netdiscover to discover all devices on the specified
arp-able networks and translate into the device information.
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/mac-to-devinfo/conffiles
/etc/config/mactodevinfo
endef
define Package/mac-to-devinfo/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) ./files/mac-to-devinfo $(1)/usr/bin
$(INSTALL_BIN) ./files/ip-to-devinfo $(1)/usr/bin
$(INSTALL_BIN) ./files/prep-devinfo $(1)/usr/bin
$(INSTALL_DIR) $(1)/usr/lib/mac-to-devinfo
$(INSTALL_BIN) ./files/devinfo-functions.sh $(1)/usr/lib/mac-to-devinfo
$(INSTALL_DIR) $(1)/usr/share/mac-to-devinfo
$(CP) ./files/macdevdb $(1)/usr/share/mac-to-devinfo
$(INSTALL_DIR) $(1)/etc/config
$(CP) ./files/mactodevinfo $(1)/etc/config
endef
define Package/smap-to-devinfo/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) ./files/smap-to-devinfo $(1)/usr/bin
endef
define Package/netdiscover-to-devinfo/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) ./files/netdiscover-to-devinfo $(1)/usr/bin
endef
$(eval $(call BuildPackage,mac-to-devinfo))
$(eval $(call BuildPackage,smap-to-devinfo))
$(eval $(call BuildPackage,netdiscover-to-devinfo))

View File

@ -0,0 +1,122 @@
#!/bin/sh
# Shell script compatibility wrappers for /sbin/uci
#
# Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
# Copyright (C) 2009 Daniel Dickinson <crazycshore@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# $UCI and $UCISTATE must be set
CONFIG_APPEND=
_C=0
LOAD_STATE=1
LIST_SEP=" "
config_load() {
local PACKAGE="$1"
local DATA
local RET
_C=0
if [ -z "$CONFIG_APPEND" ]; then
CONFIG_SECTIONS=
CONFIG_NUM_SECTIONS=0
CONFIG_SECTION=
fi
export NO_EXPORT=
DATA="$($UCI -P $UCISTATE -S -n export "$PACKAGE" 2>/dev/null)"
RET="$?"
[ "$RET" != 0 -o -z "$DATA" ] || eval "$DATA"
unset DATA
${CONFIG_SECTION:+config_cb}
return "$RET"
}
reset_cb() {
config_cb() { return 0; }
option_cb() { return 0; }
list_cb() { return 0; }
}
reset_cb
config () {
local cfgtype="$1"
local name="$2"
CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1))
name="${name:-cfg$CONFIG_NUM_SECTIONS}"
append CONFIG_SECTIONS "$name"
[ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name"
CONFIG_SECTION="$name"
eval "CONFIG_${CONFIG_SECTION}_TYPE=\"$cfgtype\""
}
option () {
local varname="$1"; shift
local value="$*"
eval "CONFIG_${CONFIG_SECTION}_${varname}=\"$value\""
[ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*"
}
list() {
local varname="$1"; shift
local value="$*"
local len
config_get len "$CONFIG_SECTION" "${varname}_LENGTH"
len="$((${len:-0} + 1))"
config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value"
config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len"
append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP"
list_cb "$varname" "$*"
}
config_get() {
case "$3" in
"") eval "echo \"\${CONFIG_${1}_${2}}\"";;
*) eval "$1=\${CONFIG_${2}_${3}}";;
esac
}
config_foreach() {
local function="$1"
[ "$#" -ge 1 ] && shift
local type="$1"
[ "$#" -ge 1 ] && shift
local section cfgtype
[ -z "$CONFIG_SECTIONS" ] && return 0
for section in ${CONFIG_SECTIONS}; do
config_get cfgtype "$section" TYPE
[ -n "$type" -a "x$cfgtype" != "x$type" ] && continue
$function "$section" "$@"
done
}
package() {
return 0
}
append() {
local var="$1"
local value="$2"
local sep="${3:- }"
eval "$var=\${$var:+\${$var}\${value:+\$sep}}\$value"
}

View File

@ -0,0 +1,29 @@
#!/bin/sh
ARP=arp
MACTODEV=mac-to-devinfo
IP=$1
if [ -z "$IP" ]; then
echo "Must specify IP address"
fi
if [ ! -x "$(which $ARP)" ]; then
do_arp() {
cat /proc/net/arp
}
ARPMACFIELD=4
else
do_arp() {
$ARP -n
}
ARPMACFIELD=3
fi
ping -q -c 2 $IP >/dev/null
MAC=$(do_arp|grep "$IP "|tr -s \ | cut -f$ARPMACFIELD -d\ )
$MACTODEV $MAC

View File

@ -0,0 +1,155 @@
#!/bin/sh
UCIBIN=uci
UCIFUNC=/usr/lib/mac-to-devinfo/devinfo-functions.sh
OVERRIDETABLE=mactodevinfo
DEVDB=macdevdb
UCICONFIG=/etc/config
OUIURL=http://standards.ieee.org/regauth/oui/oui.txt
IABURL=http://standards.ieee.org/regauth/oui/iab.txt
OUIDIR=/var/cache/mac-to-devinfo
OUIFILE=$OUIDIR/oui.txt
IABFILE=$OUIDIR/iab.txt
UCIDEVDB=/usr/share/mac-to-devinfo
UCISTATE="$(mktemp -t)"
. $UCIFUNC
MAC=$1
if [ -z "$MAC" ]; then
echo "Must specify MAC address"
exit 1
fi
parse_override() {
local cfg="$1"
config_get name "$cfg" name
config_get maclow "$cfg" maclow
config_get machigh "$cfg" machigh
config_get vendor "$cfg" vendor
config_get devtype "$cfg" devtype
config_get model "$cfg" model
config_get ouiowneroverride "$cfg" ouiowner
LOW=$(echo $maclow | sed -e 's/://g')
HIGH=$(echo $machigh | sed -e 's/://g')
if [ -z "$LOW" ] || [ -z "$HIGH" ] || [ -n "$(echo $LOW | grep -E -v '^[0-9A-Fa-f]{12}$')" ] || [ -n "$(echo $HIGH | grep -E -v '^[0-9A-Fa-f]{12}$')" ]; then
echo "Invalid mac range for $name: $ouiowneroverride $vendor $devtype $model : $LOW-$HIGH" >&2
return 1
fi
LOWMSB=$(expr substr "$LOW" 1 6)
LOWLSB=$(expr substr "$LOW" 7 6)
HIGHMSB=$(expr substr "$HIGH" 1 6)
HIGHLSB=$(expr substr "$HIGH" 7 6)
if [ -z "$LOWMSB" ] || [ -z "$LOWLSB" ] || [ -z "$HIGHMSB" ] || [ -z "$HIGHLSB" ]; then
echo "Error splitting database address strings"
return 1
fi
MACMSB=$(expr substr "$MACNUM" 1 6)
MACLSB=$(expr substr "$MACNUM" 7 6)
if [ -z "$MACMSB" ] || [ -z "$MACLSB" ]; then
echo "Error spliiting mac address string"
return 1
fi
if [ -n "$ouiowneroverride" ]; then
OUIOWNER="$ouiowneroverride"
fi
if [ $((0x$MACMSB)) -ge $((0x$LOWMSB)) ] && [ $((0x$MACMSB)) -le $((0x$HIGHMSB)) ]; then
if [ $((0x$MACLSB)) -ge $((0x$LOWLSB)) ] && [ $((0x$MACLSB)) -le $((0x$HIGHLSB)) ]; then
if [ -n "$OUTSTRING" ]; then
echo "ERROR: We already have found information '$OUTSTRING'" >&2
echo -n "and now we have: " >&2
echo "$MAC | $OUIOWNER | $vendor | $devtype | $model" >&2
return 1
else
echo "$MAC | $OUIOWNER | $vendor | $devtype | $model"
return 0
fi
fi
fi
return 0
}
if [ ! -r "$OUIFILE" ] || [ ! -r "$IABFILE" ]; then
echo "Missing IEEE Registration Authority Database. Please run prep-devinfo"
exit 1
fi
OUI="$(echo $MAC | cut -f1-3 -d: | sed -e 's/:/-/g' | tr abcdef ABCDEF )"
OUIOWNER="$(cat $OUIFILE | grep $OUI | tr -s '\t' | cut -f2- -d"$(printf '\t')" )"
if [ -z "$OUIOWNER" ] || [ "$OUIOWNER" = "IEEE REGISTRATION AUTHORITY" ]; then
if [ -n "$(cat $IABFILE | grep $OUI)" ]; then
LOWRANGE="$(echo $MAC | cut -f4-6 -d: | sed -e 's/://g' | tr abcdef ABCDEF )"
for range in $(cat $IABFILE |grep -E '[0-9A-F]{6}\-[0-9A-F]{6}' |cut -f1 -d"$(printf '\t')" ); do
LOW="$(echo $range | cut -f1 -d- )"
HIGH="$(echo $range | cut -f2 -d- )"
if [ -z "$LOW" ] || [ -z "$HIGH" ]; then
echo "Error parsing IAB table"
exit 1
fi
LOWMSB=$(expr substr "$LOW" 1 6)
LOWLSB=$(expr substr "$LOW" 7 6)
HIGHMSB=$(expr substr "$HIGH" 1 6)
HIGHLSB=$(expr substr "$HIGH" 7 6)
if [ -z "$LOWMSB" ] || [ -z "$LOWLSB" ] || [ -z "$HIGHMSB" ] || [ -z "$HIGHLSB" ]; then
echo "Error splitting registration authority IAB address strings"
exit 1
fi
MACMSB=$(expr substr "$LOWRANGE" 1 6)
MACLSB=$(expr substr "$LOWRANGE" 7 6)
if [ -z "$MACMSB" ] || [ -z "$MACLSB" ]; then
echo "Error splitting mac address string"
exit 1
fi
if [ $((0x$MACMSB)) -ge $((0x$LOWMSB)) ] && [ $((0x$MACMSB)) -le $((0x$HIGHMSB)) ]; then
if [ $((0x$MACLSB)) -ge $((0x$LOWLSB)) ] && [ $((0x$MACLSB)) -le $((0x$HIGHLSB)) ]; then
OUIOWNER="$(cat $IABFILE | grep "$LOW-$HIGH" | tr -s '\t' | cut -f3- -d"$(printf '\t')" )"
break;
fi
fi
done
fi
fi
if [ -z "$OUIOWNER" ]; then
OUIOWNER="Unknown Organization"
fi
MACNUM="$(echo $MAC |sed -e 's/://g' | tr ABCDEF abcdef )"
UCI="$UCIBIN -c $UCIDEVDB"
config_load $DEVDB
DEVSTRING=$(config_foreach parse_override mactodevinfo)
SAVEDEVSTRING="$DEVSTRING"
UCI="$UCIBIN -c $UCICONFIG"
config_load $OVERRIDETABLE
DEVSTRING=$(config_foreach parse_override mactodevinfo)
if [ -z "$DEVSTRING" ]; then
if [ -z "$SAVEDEVSTRING" ]; then
echo "$MAC | $OUIOWNER | unknown | unknown | unknown"
else
echo "$SAVEDEVSTRING"
fi
else
echo "$DEVSTRING"
fi
rm -f $UCISTATE

View File

@ -0,0 +1,19 @@
config 'mactodevinfo'
option 'name' 'Tecom Phones'
option 'maclow' '00:19:15:00:00:00'
option 'machigh' '00:19:15:ff:ff:ff'
option 'vendor' 'Vertical Communications'
option 'devtype' 'SIP devices and various'
option 'model' 'varies'
config 'mactodevinfo'
option 'name' 'Comtrend Routers'
option 'maclow' '00:30:da:47:b0:00'
option 'machigh' '00:30:da:47:dd:ff'
option 'vendor' 'Comtrend Co.'
option 'devtype' 'Networking Equipment'
option 'model' 'varies'
option 'ouiowner' 'Comtrend Co.'

View File

@ -0,0 +1,2 @@
package mactodevinfo

View File

@ -0,0 +1,26 @@
#!/bin/sh
MACTODEV=mac-to-devinfo
NETDISCOVER=netdiscover
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: netdiscover-to-devinfo IP-range Interface Timeout"
exit 1
fi
prep-devinfo
OLDIFS=$IFS
IFS='
'
for line in $($NETDISCOVER -t $3 -k -m -i $2 -r $1); do
IFS=$OLDIFS
IP=$(echo $line | tr -s \ | cut -f1 -d\ )
MAC=$(echo $line | tr -s \ | cut -f2 -d\ )
echo "$IP"" | ""$($MACTODEV $MAC)"
OLDIFS=$IFS
IFS='
'
done
IFS=$OLDIFS

View File

@ -0,0 +1,15 @@
#!/bin/sh
OUIURL=http://standards.ieee.org/regauth/oui/oui.txt
IABURL=http://standards.ieee.org/regauth/oui/iab.txt
OUIDIR=/var/cache/mac-to-devinfo
OUIFILE=$OUIDIR/oui.txt
IABFILE=$OUIDIR/iab.txt
[ -d $OUIDIR ] || mkdir -p $OUIDIR
wget -q -O $OUIFILE $OUIURL
wget -q -O $IABFILE $IABURL

View File

@ -0,0 +1,37 @@
#!/bin/sh
IPTODEV=ip-to-devinfo
SMAP=smap
if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ -z "$1" ]; then
echo "Usage: $0 IP-Range [port,port,...]"
fi
if [ -n "$2" ]; then
FIELD=1
curport="$(echo $2 | cut -f$FIELD -d, )"
while [ "$curport" != "" ]; do
PORTS="$curport $PORTS"
FIELD=$(($FIELD + 1))
curport="$(echo $2 | cut -f$FIELD -d, )"
done
fi
prep-devinfo
if [ -z "$PORTS" ]; then
PORTS=5060
fi
for port in $PORTS; do
for sip_device in $($SMAP -p $port $1 | grep -E -v 'host.? scanned' | grep 'SIP enabled' | cut -f1 -d: ); do
if [ -x "$(which httping)" ]; then
if httping -G -q -o 401,200 -c 2 -h $sip_device; then
echo "$sip_device"" | ""$($IPTODEV $sip_device)"" | ""http://$sip_device/"
continue
fi
fi
echo "$sip_device"" | ""$(IPTODEV $sip_device)"" | "" - "
done
done