[package] mac-to-devinfo updates and cleanups (#5488)

git-svn-id: svn://svn.openwrt.org/openwrt/packages@16794 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
florian 2009-07-12 10:55:29 +00:00
parent e602b72d3a
commit 3ba2924807
7 changed files with 161 additions and 55 deletions

View File

@ -1,49 +1,56 @@
#
# Copyright (C) 2009 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=mac-to-devinfo PKG_NAME:=mac-to-devinfo
PKG_VERSION:=1.0.0 PKG_VERSION:=1.0.0
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk
define Package/mac-to-devinfo define Package/mac-to-devinfo
SECTION:=net SECTION:=net
CATEGORY:=Network CATEGORY:=Network
TITLE:=MAC Address to Device Information TITLE:=MAC Address to Device Information
endef endef
define Package/mac-to-devinfo/description define Package/mac-to-devinfo/description
Scripts to take a mac address (or ip if the ip is in the arp cache) 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 and translate it into device information (mostly OUI owner, from the
IEEE data files, but more information may be available for specific IEEE data files, but more information may be available for specific
devices/vendors). devices/vendors).
endef endef
define Package/smap-to-devinfo define Package/smap-to-devinfo
SECTION:=net SECTION:=net
CATEGORY:=Network CATEGORY:=Network
DEPENDS:=mac-to-devinfo +smap +httping DEPENDS:=mac-to-devinfo +smap +httping
TITLE:=SIP Device Information from Scan TITLE:=SIP Device Information from Scan
endef endef
define Package/smap-to-devinfo/description define Package/smap-to-devinfo/description
A script to use smap to discover all SIP devices on the networks 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 (provided ICMP and SIP are allowed to the network from the host) and
translate (through the ip then mac) into the device information. translate (through the ip then mac) into the device information.
endef endef
define Package/netdiscover-to-devinfo define Package/netdiscover-to-devinfo
SECTION:=net SECTION:=net
CATEGORY:=Network CATEGORY:=Network
DEPENDS:=mac-to-devinfo +netdiscover DEPENDS:=mac-to-devinfo +netdiscover
TITLE:=Device Information from Scan for MAC addresses TITLE:=Device Information from Scan for MAC addresses
endef endef
define Package/netdiscover-to-devinfo/description define Package/netdiscover-to-devinfo/description
A script to use netdiscover to discover all devices on the specified A script to use netdiscover to discover all devices on the specified
arp-able networks and translate into the device information. arp-able networks and translate into the device information.
endef endef
define Build/Prepare define Build/Prepare
@ -64,6 +71,7 @@ define Package/mac-to-devinfo/install
$(INSTALL_BIN) ./files/mac-to-devinfo $(1)/usr/bin $(INSTALL_BIN) ./files/mac-to-devinfo $(1)/usr/bin
$(INSTALL_BIN) ./files/ip-to-devinfo $(1)/usr/bin $(INSTALL_BIN) ./files/ip-to-devinfo $(1)/usr/bin
$(INSTALL_BIN) ./files/prep-devinfo $(1)/usr/bin $(INSTALL_BIN) ./files/prep-devinfo $(1)/usr/bin
$(INSTALL_BIN) ./files/clean-devinfo $(1)/usr/bin
$(INSTALL_DIR) $(1)/usr/lib/mac-to-devinfo $(INSTALL_DIR) $(1)/usr/lib/mac-to-devinfo
$(INSTALL_BIN) ./files/devinfo-functions.sh $(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 $(INSTALL_DIR) $(1)/usr/share/mac-to-devinfo

View File

@ -3,12 +3,42 @@
ARP=arp ARP=arp
MACTODEV=mac-to-devinfo MACTODEV=mac-to-devinfo
IP=$1 usage() {
echo "Usage: $0 [-i interface] [-x port] IP-address"
}
if [ "$1" == "-i" ]; then
INTERFACE="$2"
if [ -z "$INTERFACE" ]; then
echo "-i without interface"
usage
exit 1
fi
shift
shift
fi
if [ "$1" == "-x" ]; then
PORT="-x $2"
if [ -z "$PORT" ]; then
echo "-x without the port"
usage
exit 1
fi
shift
shift
fi
IP="$1"
shift
if [ -z "$IP" ]; then if [ -z "$IP" ]; then
echo "Must specify IP address" echo "Must specify IP address"
usage
exit 1
fi fi
if [ ! -x "$(which $ARP)" ]; then if [ ! -x "$(which $ARP)" ]; then
do_arp() { do_arp() {
cat /proc/net/arp cat /proc/net/arp
@ -21,9 +51,13 @@ else
ARPMACFIELD=3 ARPMACFIELD=3
fi fi
ping -q -c 2 $IP >/dev/null if [ -z "$INTERFACE" ]; then
MAC=$(do_arp|grep "$IP "|tr -s \ | cut -f$ARPMACFIELD -d\ ) ping -q -c 2 $IP >/dev/null
MAC=$(do_arp|grep "$IP "|tr -s \ | cut -f$ARPMACFIELD -d\ )
else
MAC=$(arping -f -c 5 -I $INTERFACE $IP | grep 'Unicast reply from' | cut -f2 -d \[ | cut -f1 -d\])
fi
$MACTODEV $MAC $MACTODEV $PORT $MAC

View File

@ -19,13 +19,27 @@ UCISTATE="$(mktemp -t)"
. $UCIFUNC . $UCIFUNC
MAC=$1
if [ "$1" == "-x" ]; then
PORT="$2"
if [ -z "$PORT" ]; then
echo "-x without the port"
echo "Usage: $0 [-x port] MAC-address"
exit 1
fi
shift
shift
fi
MAC="$1"
if [ -z "$MAC" ]; then if [ -z "$MAC" ]; then
echo "Must specify MAC address" echo "Unknown MAC address | Unknown | unknown | unknown | unknown"
exit 1 exit 1
fi fi
MAC=$(echo $MAC | sed -e 's/^\([0-9]\):/0\1:/g' | sed -e 's/:\([0-9]\)$/:0\1/g' | sed -e 's/:\([0-9]\):/:0\1:/g')
parse_override() { parse_override() {
local cfg="$1" local cfg="$1"
config_get name "$cfg" name config_get name "$cfg" name
@ -65,6 +79,18 @@ parse_override() {
fi fi
if [ $((0x$MACMSB)) -ge $((0x$LOWMSB)) ] && [ $((0x$MACMSB)) -le $((0x$HIGHMSB)) ]; then 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 [ $((0x$MACLSB)) -ge $((0x$LOWLSB)) ] && [ $((0x$MACLSB)) -le $((0x$HIGHLSB)) ]; then
if [ "$PORT" == "5060" ]; then
if [ "$vendor" == "Vertical Communications" ]; then
devtype="VoIP Phone"
model="IP200x"
fi
fi
if [ "$PORT" == "6060" ]; then
if [ "$vendor" == "Vertical Communications" ]; then
devtype="VoIP PBX"
model="Xcelerator IP"
fi
fi
if [ -n "$OUTSTRING" ]; then if [ -n "$OUTSTRING" ]; then
echo "ERROR: We already have found information '$OUTSTRING'" >&2 echo "ERROR: We already have found information '$OUTSTRING'" >&2
echo -n "and now we have: " >&2 echo -n "and now we have: " >&2

View File

@ -1,19 +1,8 @@
config 'mactodevinfo' config 'mactodevinfo'
option 'name' 'Tecom Phones'
option 'maclow' '00:19:15:00:00:00' option 'maclow' '00:19:15:00:00:00'
option 'machigh' '00:19:15:ff:ff:ff' option 'machigh' '00:19:15:ff:ff:ff'
option 'vendor' 'Vertical Communications' option 'vendor' 'Vertical Communications'
option 'devtype' 'SIP devices and various' option 'devtype' 'SIP devices'
option 'model' 'varies' 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

@ -10,6 +10,6 @@ IABFILE=$OUIDIR/iab.txt
[ -d $OUIDIR ] || mkdir -p $OUIDIR [ -d $OUIDIR ] || mkdir -p $OUIDIR
wget -q -O $OUIFILE $OUIURL [ -r $OUIFILE ] || wget -q -O $OUIFILE $OUIURL
wget -q -O $IABFILE $IABURL [ -r $IABFILE ] || wget -q -O $IABFILE $IABURL

View File

@ -2,19 +2,64 @@
IPTODEV=ip-to-devinfo IPTODEV=ip-to-devinfo
SMAP=smap SMAP=smap
OUIDIR=/var/cache/mac-to-devinfo
if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ -z "$1" ]; then XIP_SCANS=FALSE
echo "Usage: $0 IP-Range [port,port,...]"
usage() {
echo "Usage: $0 IP-Range [-r ratelimit] [-i interface] [-x] [port,port,...]"
}
if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ "$3" == "-h" ] || [ -z "$1" ]; then
usage
exit 1
fi fi
if [ -n "$2" ]; then IPRANGE="$1"
FIELD=1 shift
curport="$(echo $2 | cut -f$FIELD -d, )"
while [ "$curport" != "" ]; do if [ "$1" == "-r" ]; then
PORTS="$curport $PORTS" RATELIMIT="-r $2"
FIELD=$(($FIELD + 1)) if [ -z "$RATELIMIT" ]; then
curport="$(echo $2 | cut -f$FIELD -d, )" echo "-r without a ratelimit"
done usage
exit 1
fi
shift
shift
fi
if [ "$1" == "-i" ]; then
INTERFACE="-i $2"
if [ -z "$INTERFACE" ]; then
echo "-i without interface"
usage
exit 1
fi
shift
shift
fi
if [ "$1" == "-x" ]; then
XIP_SCANS=TRUE
shift
fi
if [ -n "$1" ]; then
PORTLIST="$1"
if [ -z "$(echo $PORTLIST | grep ',')" ]; then
PORTS="$PORTLIST"
else
FIELD=1
oldcurport=""
curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
while [ "$curport" != "$oldcurport" ]; do
PORTS="$curport $PORTS"
FIELD=$(($FIELD + 1))
oldcurport="$(echo $PORTLIST | cut -f$FIELD -d, )"
curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
done
fi
fi fi
prep-devinfo prep-devinfo
@ -24,14 +69,18 @@ if [ -z "$PORTS" ]; then
fi fi
for port in $PORTS; do 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 [ "$XIP_SCANS" == "TRUE" ]; then
XIP_PORT="-x $port"
fi
for sip_device in $($SMAP $RATELIMIT -p $port $IPRANGE | grep -E -v 'host.? scanned' | grep 'SIP enabled' | cut -f1 -d: ); do
if [ -x "$(which httping)" ]; then if [ -x "$(which httping)" ]; then
if httping -G -q -o 401,200 -c 2 -h $sip_device; then if httping -G -q -o 401,200 -c 2 -h $sip_device; then
echo "$sip_device"" | ""$($IPTODEV $sip_device)"" | ""http://$sip_device/" echo "$sip_device"" | ""$($IPTODEV $INTERFACE $XIP_PORT $sip_device)"" | ""http://$sip_device/"
continue continue
fi fi
fi fi
echo "$sip_device"" | ""$(IPTODEV $sip_device)"" | "" - " echo "$sip_device"" | ""$(IPTODEV $XIP_PORT $sip_device)"" | "" - "
done done
done done