[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,8 +1,15 @@
#
# 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)
@ -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

View 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
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

View File

@ -19,12 +19,26 @@ UCISTATE="$(mktemp -t)"
. $UCIFUNC
MAC=$1
if [ -z "$MAC" ]; then
echo "Must specify MAC address"
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 "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"
@ -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

View 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.'

View 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

View File

@ -2,20 +2,65 @@
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
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
curport="$(echo $2 | cut -f$FIELD -d, )"
while [ "$curport" != "" ]; do
oldcurport=""
curport="$(echo $PORTLIST | cut -f$FIELD -d, )"
while [ "$curport" != "$oldcurport" ]; do
PORTS="$curport $PORTS"
FIELD=$(($FIELD + 1))
curport="$(echo $2 | cut -f$FIELD -d, )"
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