From: Florian Fainelli Date: Sun, 12 Jul 2009 10:55:29 +0000 (+0000) Subject: [package] mac-to-devinfo updates and cleanups (#5488) X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fsvn-archive%2Farchive.git;a=commitdiff_plain;h=07e52f5daffed3f2e8199933fbf7daf6d038641c [package] mac-to-devinfo updates and cleanups (#5488) SVN-Revision: 16794 --- diff --git a/net/mac-to-devinfo/Makefile b/net/mac-to-devinfo/Makefile index 7d4c4e111d..0ca7a57113 100644 --- a/net/mac-to-devinfo/Makefile +++ b/net/mac-to-devinfo/Makefile @@ -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 PKG_NAME:=mac-to-devinfo PKG_VERSION:=1.0.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 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 + 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). + 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 + 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. + 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 + 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. + 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 @@ -64,6 +71,7 @@ define Package/mac-to-devinfo/install $(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_BIN) ./files/clean-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 diff --git a/net/mac-to-devinfo/files/ip-to-devinfo b/net/mac-to-devinfo/files/ip-to-devinfo index 2ac2677b2d..874dc383ed 100644 --- a/net/mac-to-devinfo/files/ip-to-devinfo +++ b/net/mac-to-devinfo/files/ip-to-devinfo @@ -3,12 +3,42 @@ ARP=arp 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 echo "Must specify IP address" + usage + exit 1 fi + if [ ! -x "$(which $ARP)" ]; then do_arp() { cat /proc/net/arp @@ -21,9 +51,13 @@ else ARPMACFIELD=3 fi -ping -q -c 2 $IP >/dev/null -MAC=$(do_arp|grep "$IP "|tr -s \ | cut -f$ARPMACFIELD -d\ ) +if [ -z "$INTERFACE" ]; then + 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 diff --git a/net/mac-to-devinfo/files/mac-to-devinfo b/net/mac-to-devinfo/files/mac-to-devinfo index 37d132e0c0..60884e9aae 100644 --- a/net/mac-to-devinfo/files/mac-to-devinfo +++ b/net/mac-to-devinfo/files/mac-to-devinfo @@ -19,13 +19,27 @@ UCISTATE="$(mktemp -t)" . $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 - echo "Must specify MAC address" + echo "Unknown MAC address | Unknown | unknown | unknown | unknown" exit 1 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() { local cfg="$1" config_get name "$cfg" name @@ -65,6 +79,18 @@ parse_override() { 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 [ "$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 echo "ERROR: We already have found information '$OUTSTRING'" >&2 echo -n "and now we have: " >&2 diff --git a/net/mac-to-devinfo/files/macdevdb b/net/mac-to-devinfo/files/macdevdb index 93166c1fb4..8bb8873594 100644 --- a/net/mac-to-devinfo/files/macdevdb +++ b/net/mac-to-devinfo/files/macdevdb @@ -1,19 +1,8 @@ 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 'devtype' 'SIP devices' 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.' - - diff --git a/net/mac-to-devinfo/files/netdiscover-to-devinfo b/net/mac-to-devinfo/files/netdiscover-to-devinfo index d8908fad5f..d6783529c0 100644 --- a/net/mac-to-devinfo/files/netdiscover-to-devinfo +++ b/net/mac-to-devinfo/files/netdiscover-to-devinfo @@ -23,4 +23,4 @@ for line in $($NETDISCOVER -t $3 -k -m -i $2 -r $1); do done IFS=$OLDIFS - \ No newline at end of file + diff --git a/net/mac-to-devinfo/files/prep-devinfo b/net/mac-to-devinfo/files/prep-devinfo index 0abf633bac..45e958cbc5 100644 --- a/net/mac-to-devinfo/files/prep-devinfo +++ b/net/mac-to-devinfo/files/prep-devinfo @@ -10,6 +10,6 @@ IABFILE=$OUIDIR/iab.txt [ -d $OUIDIR ] || mkdir -p $OUIDIR -wget -q -O $OUIFILE $OUIURL -wget -q -O $IABFILE $IABURL +[ -r $OUIFILE ] || wget -q -O $OUIFILE $OUIURL +[ -r $IABFILE ] || wget -q -O $IABFILE $IABURL diff --git a/net/mac-to-devinfo/files/smap-to-devinfo b/net/mac-to-devinfo/files/smap-to-devinfo index 191bde4bd9..5bfc13fc67 100644 --- a/net/mac-to-devinfo/files/smap-to-devinfo +++ b/net/mac-to-devinfo/files/smap-to-devinfo @@ -2,19 +2,64 @@ IPTODEV=ip-to-devinfo SMAP=smap +OUIDIR=/var/cache/mac-to-devinfo -if [ "$1" == "-h" ] || [ "$2" == "-h" ] || [ -z "$1" ]; then - echo "Usage: $0 IP-Range [port,port,...]" +XIP_SCANS=FALSE + +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 -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 +IPRANGE="$1" +shift + +if [ "$1" == "-r" ]; then + RATELIMIT="-r $2" + if [ -z "$RATELIMIT" ]; then + echo "-r without a ratelimit" + 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 prep-devinfo @@ -24,14 +69,18 @@ if [ -z "$PORTS" ]; then 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 [ "$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 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 fi fi - echo "$sip_device"" | ""$(IPTODEV $sip_device)"" | "" - " + echo "$sip_device"" | ""$(IPTODEV $XIP_PORT $sip_device)"" | "" - " done done