+#
+# 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
$(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
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
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
. $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
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
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.'
-
-
done
IFS=$OLDIFS
-
\ No newline at end of file
+
[ -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
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
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