From c6e40ca384de5bba1e0e3132a61c3d8ccbfed2cc Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 18 Jul 2009 00:41:44 +0000 Subject: [PATCH] [package] add netsmap-to-devinfo (#5537) git-svn-id: svn://svn.openwrt.org/openwrt/packages@16888 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- net/mac-to-devinfo/Makefile | 1 + net/mac-to-devinfo/files/clean-devinfo | 5 + net/mac-to-devinfo/files/netdiscover-to-devinfo | 41 +++++-- net/mac-to-devinfo/files/netsmap-to-devinfo | 139 ++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 net/mac-to-devinfo/files/netsmap-to-devinfo diff --git a/net/mac-to-devinfo/Makefile b/net/mac-to-devinfo/Makefile index 0ca7a5711..4736fb8ec 100644 --- a/net/mac-to-devinfo/Makefile +++ b/net/mac-to-devinfo/Makefile @@ -83,6 +83,7 @@ endef define Package/smap-to-devinfo/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) ./files/smap-to-devinfo $(1)/usr/bin + $(INSTALL_BIN) ./files/netsmap-to-devinfo $(1)/usr/bin endef define Package/netdiscover-to-devinfo/install diff --git a/net/mac-to-devinfo/files/clean-devinfo b/net/mac-to-devinfo/files/clean-devinfo index 706c8ec44..b3aba91dc 100644 --- a/net/mac-to-devinfo/files/clean-devinfo +++ b/net/mac-to-devinfo/files/clean-devinfo @@ -3,3 +3,8 @@ OUIDIR=/var/cache/mac-to-devinfo rm -rf $OUIDIR +#!/bin/sh + +OUIDIR=/var/cache/mac-to-devinfo + +rm -rf $OUIDIR diff --git a/net/mac-to-devinfo/files/netdiscover-to-devinfo b/net/mac-to-devinfo/files/netdiscover-to-devinfo index d6783529c..7029dd311 100644 --- a/net/mac-to-devinfo/files/netdiscover-to-devinfo +++ b/net/mac-to-devinfo/files/netdiscover-to-devinfo @@ -1,26 +1,51 @@ #!/bin/sh MACTODEV=mac-to-devinfo -NETDISCOVER=netdiscover if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "Usage: netdiscover-to-devinfo IP-range Interface Timeout" + echo "Usage: netdiscover-to-devinfo IP-range Interface Timeout [-r repeats] [-s sleep_between_arp_requests]" exit 1 fi prep-devinfo -OLDIFS=$IFS IFS=' ' -for line in $($NETDISCOVER -t $3 -k -m -i $2 -r $1); do - IFS=$OLDIFS + +IPRANGE=$1 +IFACE=$2 +TIMEOUT=$3 + +shift 3 + +while getopts "r:s:h" param; do + case "$param" in + h) + usage + exit 1 + ;; + r) + REPEATS=" -c $OPTARG" + ;; + s) + SLEEPREQ="-s $OPTARG" + ;; + ?|*) + usage + exit 1 + break + ;; + + esac +done + + +for line in $(sh -c "netdiscover -t $TIMEOUT-k -m -i $IFACE -r $IPRANGE $REPEATS $SLEEPREQ 2>/dev/null" | grep -E '[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?'); do + unset IFS IP=$(echo $line | tr -s \ | cut -f1 -d\ ) MAC=$(echo $line | tr -s \ | cut -f2 -d\ ) echo "$IP"" | ""$($MACTODEV $MAC)" - OLDIFS=$IFS IFS=' ' done -IFS=$OLDIFS - +unset IFS diff --git a/net/mac-to-devinfo/files/netsmap-to-devinfo b/net/mac-to-devinfo/files/netsmap-to-devinfo new file mode 100644 index 000000000..5df1e2a8e --- /dev/null +++ b/net/mac-to-devinfo/files/netsmap-to-devinfo @@ -0,0 +1,139 @@ +#!/bin/sh + +MACTODEV=mac-to-devinfo +IPTODEV=ip-to-devinfo + +usage() { + echo "$0: -i interferace -r ip-range [options]" + echo "" + echo "-r ip-range range to probe (CIDR, e.g. 192.168.2.0/24)" + echo "-i interface interface to use in scan" + echo "-t timeout time to rate for arp responses for device detection" + echo "-p port[,port...] command-separated lists of ports to scan for SIP responses" + echo "-c repeat_count Number of times to send each request (default 1)" + echo "-s sleepreq ms to wait between sending arp requests" + echo "-x Assume we're running on an Xcelerator IP" + echo "-h help" +} + + +while getopts "r:i:t:p:c:s:xh" param; do + case "$param" in + h) + usage + exit 1 + ;; + r) + IPRANGE=$OPTARG + ;; + i) + INTERFACE=$OPTARG + ;; + t) + TIMEOUT=$OPTARG + ;; + p) + PORTARG=$OPTARG + ;; + c) + REPEATCOUNT=$OPTARG + ;; + s) + SLEEPREQ="-s $OPTARG" + ;; + x) + XIP=TRUE + ;; + ?|*) + usage + exit 1 + break + ;; + + esac +done + +if [ "$IPRANGE" = "" ]; then + echo "Must specify an ip range" + usage + exit 1 +fi + +if [ "$INTERFACE" = "" ]; then + echo "Must speciy the interface" + usage + exit 1 +fi + +if [ "$TIMEOUT" = "" ]; then + TIMEOUT=20 + usage +fi + +unset PORTS + +if [ -n "$PORTARG" ]; then + PORTLIST="$PORTARG" + + 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 + +IFS=' +' + +if [ -n "$REPEATCOUNT" ]; then + REPEAT="-c $REPEATCOUNT" +fi + +for line in $(sh -c "netdiscover -t $TIMEOUT -k -m -i $INTERFACE -r $IPRANGE $REPEAT $SLEEPREQ 2>/dev/null" | grep -E '[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?.[0-9]([0-9]?[0-9])?'); do + unset IFS + IP=$(echo $line | tr -s \ | cut -f1 -d\ ) + MAC=$(echo $line | tr -s \ | cut -f2 -d\ ) + + if [ -n "$PORTS" ]; then + for port in $PORTS; do + + if [ "$XIP" = "TRUE" ]; then + XIP_PORT="-x $port" + fi + for sip_device in $(smap -p $port $IP