[package] mac-to-devinfo updates and cleanups (#5488)
authorFlorian Fainelli <florian@openwrt.org>
Sun, 12 Jul 2009 10:55:29 +0000 (10:55 +0000)
committerFlorian Fainelli <florian@openwrt.org>
Sun, 12 Jul 2009 10:55:29 +0000 (10:55 +0000)
SVN-Revision: 16794

net/mac-to-devinfo/Makefile
net/mac-to-devinfo/files/ip-to-devinfo
net/mac-to-devinfo/files/mac-to-devinfo
net/mac-to-devinfo/files/macdevdb
net/mac-to-devinfo/files/netdiscover-to-devinfo
net/mac-to-devinfo/files/prep-devinfo
net/mac-to-devinfo/files/smap-to-devinfo

index 7d4c4e111dd44c5c9520f9c84824f4c7e72c853b..0ca7a57113aa4425229b13476ac63cd8c4bcb2a3 100644 (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
 
 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
index 2ac2677b2d890979e9253c4b76027d96ecd6440f..874dc383edf71bdf7fbf4910cf3d688ffd6456a3 100644 (file)
@@ -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
 
 
index 37d132e0c0b35ba1d9ecb5e13293e1a58898d3fc..60884e9aae3ebb463c3bb0749c0a53007489297d 100644 (file)
@@ -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
index 93166c1fb482272e15dc6679290214dcb6be3e97..8bb88735946f600b73f1cea9b7a1e041438be0ff 100644 (file)
@@ -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.'
-
-
index d8908fad5fb57bbf68d1113077158052cffc6378..d6783529c03074088769f8da5463e62687cf8c43 100644 (file)
@@ -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
+
index 0abf633bac867ff4c26a3616f62e3577b046a468..45e958cbc5ff2f3a8c32d0864d5390f2890ce1a4 100644 (file)
@@ -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
 
index 191bde4bd968822c28ecfc40320bd9b541c3df56..5bfc13fc6791c0b123d4f4400ab284103cf0ffaf 100644 (file)
@@ -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