From a11e44eba85e2647a26966122f84eb07fc1f0523 Mon Sep 17 00:00:00 2001 From: Forest Crossman Date: Sat, 21 Jun 2014 14:14:56 -0400 Subject: [PATCH 1/2] mac-to-devinfo: import from packages Signed-off-by: Forest Crossman --- net/mac-to-devinfo/Makefile | 98 +++++++++ net/mac-to-devinfo/files/clean-devinfo | 26 +++ net/mac-to-devinfo/files/devinfo-functions.sh | 122 +++++++++++ net/mac-to-devinfo/files/ip-to-devinfo | 80 +++++++ net/mac-to-devinfo/files/mac-to-devinfo | 197 ++++++++++++++++++ net/mac-to-devinfo/files/macdevdb | 8 + net/mac-to-devinfo/files/mactodevinfo | 2 + .../files/netdiscover-to-devinfo | 67 ++++++ net/mac-to-devinfo/files/netsmap-to-devinfo | 156 ++++++++++++++ net/mac-to-devinfo/files/prep-devinfo | 31 +++ net/mac-to-devinfo/files/smap-to-devinfo | 102 +++++++++ 11 files changed, 889 insertions(+) create mode 100644 net/mac-to-devinfo/Makefile create mode 100644 net/mac-to-devinfo/files/clean-devinfo create mode 100644 net/mac-to-devinfo/files/devinfo-functions.sh create mode 100644 net/mac-to-devinfo/files/ip-to-devinfo create mode 100644 net/mac-to-devinfo/files/mac-to-devinfo create mode 100644 net/mac-to-devinfo/files/macdevdb create mode 100644 net/mac-to-devinfo/files/mactodevinfo create mode 100644 net/mac-to-devinfo/files/netdiscover-to-devinfo create mode 100644 net/mac-to-devinfo/files/netsmap-to-devinfo create mode 100644 net/mac-to-devinfo/files/prep-devinfo create mode 100644 net/mac-to-devinfo/files/smap-to-devinfo diff --git a/net/mac-to-devinfo/Makefile b/net/mac-to-devinfo/Makefile new file mode 100644 index 00000000000000..8b512f16dd321a --- /dev/null +++ b/net/mac-to-devinfo/Makefile @@ -0,0 +1,98 @@ +# +# 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:=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 + MAINTAINER:=Daniel Dickinson +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). +endef + +define Package/smap-to-devinfo + SECTION:=net + CATEGORY:=Network + SUBMENU:=Telephony + 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. +endef + +define Package/netdiscover-to-devinfo + 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. +endef + +define Build/Prepare +endef + +define Build/Configure +endef + +define Build/Compile +endef + +define Package/mac-to-devinfo/conffiles +/etc/config/mactodevinfo +endef + +define Package/mac-to-devinfo/install + $(INSTALL_DIR) $(1)/usr/bin + $(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 + $(CP) ./files/macdevdb $(1)/usr/share/mac-to-devinfo + $(INSTALL_DIR) $(1)/etc/config + $(CP) ./files/mactodevinfo $(1)/etc/config +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 + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) ./files/netdiscover-to-devinfo $(1)/usr/bin +endef + +$(eval $(call BuildPackage,mac-to-devinfo)) +$(eval $(call BuildPackage,smap-to-devinfo)) +$(eval $(call BuildPackage,netdiscover-to-devinfo)) diff --git a/net/mac-to-devinfo/files/clean-devinfo b/net/mac-to-devinfo/files/clean-devinfo new file mode 100644 index 00000000000000..a34411a9a01be7 --- /dev/null +++ b/net/mac-to-devinfo/files/clean-devinfo @@ -0,0 +1,26 @@ +#!/bin/sh +# clean-devinfo - clean up after MAC IEEE and custom information +# Copyright (C) 2009 Daniel Dickinson + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +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/devinfo-functions.sh b/net/mac-to-devinfo/files/devinfo-functions.sh new file mode 100644 index 00000000000000..fc29334a86f49a --- /dev/null +++ b/net/mac-to-devinfo/files/devinfo-functions.sh @@ -0,0 +1,122 @@ +#!/bin/sh +# Shell script compatibility wrappers for /sbin/uci +# +# Copyright (C) 2008 Felix Fietkau +# Copyright (C) 2009 Daniel Dickinson +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# $UCI and $UCISTATE must be set + +CONFIG_APPEND= +_C=0 +LOAD_STATE=1 +LIST_SEP=" " + +config_load() { + local PACKAGE="$1" + local DATA + local RET + + _C=0 + + if [ -z "$CONFIG_APPEND" ]; then + CONFIG_SECTIONS= + CONFIG_NUM_SECTIONS=0 + CONFIG_SECTION= + fi + export NO_EXPORT= + DATA="$($UCI -P $UCISTATE -S -n export "$PACKAGE" 2>/dev/null)" + RET="$?" + [ "$RET" != 0 -o -z "$DATA" ] || eval "$DATA" + unset DATA + + ${CONFIG_SECTION:+config_cb} + return "$RET" +} + +reset_cb() { + config_cb() { return 0; } + option_cb() { return 0; } + list_cb() { return 0; } +} +reset_cb +config () { + local cfgtype="$1" + local name="$2" + + CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1)) + name="${name:-cfg$CONFIG_NUM_SECTIONS}" + append CONFIG_SECTIONS "$name" + [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name" + CONFIG_SECTION="$name" + eval "CONFIG_${CONFIG_SECTION}_TYPE=\"$cfgtype\"" +} + +option () { + local varname="$1"; shift + local value="$*" + + eval "CONFIG_${CONFIG_SECTION}_${varname}=\"$value\"" + [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*" +} + +list() { + local varname="$1"; shift + local value="$*" + local len + + config_get len "$CONFIG_SECTION" "${varname}_LENGTH" + len="$((${len:-0} + 1))" + config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value" + config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len" + append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP" + list_cb "$varname" "$*" +} + +config_get() { + case "$3" in + "") eval "echo \"\${CONFIG_${1}_${2}}\"";; + *) eval "$1=\${CONFIG_${2}_${3}}";; + esac +} + +config_foreach() { + local function="$1" + [ "$#" -ge 1 ] && shift + local type="$1" + [ "$#" -ge 1 ] && shift + local section cfgtype + + [ -z "$CONFIG_SECTIONS" ] && return 0 + for section in ${CONFIG_SECTIONS}; do + config_get cfgtype "$section" TYPE + [ -n "$type" -a "x$cfgtype" != "x$type" ] && continue + $function "$section" "$@" + done +} + +package() { + return 0 +} + +append() { + local var="$1" + local value="$2" + local sep="${3:- }" + + eval "$var=\${$var:+\${$var}\${value:+\$sep}}\$value" +} + diff --git a/net/mac-to-devinfo/files/ip-to-devinfo b/net/mac-to-devinfo/files/ip-to-devinfo new file mode 100644 index 00000000000000..eb4d851589202d --- /dev/null +++ b/net/mac-to-devinfo/files/ip-to-devinfo @@ -0,0 +1,80 @@ +#!/bin/sh +# ip-to-devinfo - IP (through arping or ping and arp cache) to MAC IEEE and +# custom information +# Copyright (C) 2009 Daniel Dickinson + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +ARP=arp +MACTODEV=mac-to-devinfo + +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=4 +else + do_arp() { + $ARP -n + } + 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 $PORT $MAC + + diff --git a/net/mac-to-devinfo/files/mac-to-devinfo b/net/mac-to-devinfo/files/mac-to-devinfo new file mode 100644 index 00000000000000..cce253a94cd478 --- /dev/null +++ b/net/mac-to-devinfo/files/mac-to-devinfo @@ -0,0 +1,197 @@ +#!/bin/sh +# mac-to-devinfo - MAC IEEE and custom information +# Copyright (C) 2009 Daniel Dickinson + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +UCIBIN=uci +UCIFUNC=/usr/lib/mac-to-devinfo/devinfo-functions.sh +OVERRIDETABLE=mactodevinfo +DEVDB=macdevdb +UCICONFIG=/etc/config + +OUIURL=http://standards.ieee.org/regauth/oui/oui.txt +IABURL=http://standards.ieee.org/regauth/oui/iab.txt + +OUIDIR=/var/cache/mac-to-devinfo + +OUIFILE=$OUIDIR/oui.txt +IABFILE=$OUIDIR/iab.txt + +UCIDEVDB=/usr/share/mac-to-devinfo +UCISTATE="$(mktemp -t)" + +. $UCIFUNC + + +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" + config_get name "$cfg" name + config_get maclow "$cfg" maclow + config_get machigh "$cfg" machigh + config_get vendor "$cfg" vendor + config_get devtype "$cfg" devtype + config_get model "$cfg" model + config_get ouiowneroverride "$cfg" ouiowner + LOW=$(echo $maclow | sed -e 's/://g') + HIGH=$(echo $machigh | sed -e 's/://g') + if [ -z "$LOW" ] || [ -z "$HIGH" ] || [ -n "$(echo $LOW | grep -E -v '^[0-9A-Fa-f]{12}$')" ] || [ -n "$(echo $HIGH | grep -E -v '^[0-9A-Fa-f]{12}$')" ]; then + echo "Invalid mac range for $name: $ouiowneroverride $vendor $devtype $model : $LOW-$HIGH" >&2 + return 1 + fi + + LOWMSB=$(expr substr "$LOW" 1 6) + LOWLSB=$(expr substr "$LOW" 7 6) + HIGHMSB=$(expr substr "$HIGH" 1 6) + HIGHLSB=$(expr substr "$HIGH" 7 6) + + if [ -z "$LOWMSB" ] || [ -z "$LOWLSB" ] || [ -z "$HIGHMSB" ] || [ -z "$HIGHLSB" ]; then + echo "Error splitting database address strings" + return 1 + fi + + MACMSB=$(expr substr "$MACNUM" 1 6) + MACLSB=$(expr substr "$MACNUM" 7 6) + + if [ -z "$MACMSB" ] || [ -z "$MACLSB" ]; then + echo "Error spliiting mac address string" + return 1 + fi + + if [ -n "$ouiowneroverride" ]; then + OUIOWNER="$ouiowneroverride" + 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 + echo "$MAC | $OUIOWNER | $vendor | $devtype | $model" >&2 + return 1 + else + echo "$MAC | $OUIOWNER | $vendor | $devtype | $model" + return 0 + fi + fi + fi + return 0 +} + +if [ ! -r "$OUIFILE" ] || [ ! -r "$IABFILE" ]; then + echo "Missing IEEE Registration Authority Database. Please run prep-devinfo" + exit 1 +fi + +OUI="$(echo $MAC | cut -f1-3 -d: | sed -e 's/:/-/g' | tr abcdef ABCDEF )" + +OUIOWNER="$(cat $OUIFILE | grep $OUI | tr -s '\t' | cut -f2- -d"$(printf '\t')" )" + +if [ -z "$OUIOWNER" ] || [ "$OUIOWNER" = "IEEE REGISTRATION AUTHORITY" ]; then + if [ -n "$(cat $IABFILE | grep $OUI)" ]; then + LOWRANGE="$(echo $MAC | cut -f4-6 -d: | sed -e 's/://g' | tr abcdef ABCDEF )" + for range in $(cat $IABFILE |grep -E '[0-9A-F]{6}\-[0-9A-F]{6}' |cut -f1 -d"$(printf '\t')" ); do + LOW="$(echo $range | cut -f1 -d- )" + HIGH="$(echo $range | cut -f2 -d- )" + if [ -z "$LOW" ] || [ -z "$HIGH" ]; then + echo "Error parsing IAB table" + exit 1 + + fi + LOWMSB=$(expr substr "$LOW" 1 6) + LOWLSB=$(expr substr "$LOW" 7 6) + HIGHMSB=$(expr substr "$HIGH" 1 6) + HIGHLSB=$(expr substr "$HIGH" 7 6) + + if [ -z "$LOWMSB" ] || [ -z "$LOWLSB" ] || [ -z "$HIGHMSB" ] || [ -z "$HIGHLSB" ]; then + echo "Error splitting registration authority IAB address strings" + exit 1 + fi + + MACMSB=$(expr substr "$LOWRANGE" 1 6) + MACLSB=$(expr substr "$LOWRANGE" 7 6) + + if [ -z "$MACMSB" ] || [ -z "$MACLSB" ]; then + echo "Error splitting mac address string" + exit 1 + 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 + OUIOWNER="$(cat $IABFILE | grep "$LOW-$HIGH" | tr -s '\t' | cut -f3- -d"$(printf '\t')" )" + break; + fi + fi + done + fi +fi + +if [ -z "$OUIOWNER" ]; then + OUIOWNER="Unknown Organization" +fi + +MACNUM="$(echo $MAC |sed -e 's/://g' | tr ABCDEF abcdef )" + +UCI="$UCIBIN -c $UCIDEVDB" +config_load $DEVDB +DEVSTRING=$(config_foreach parse_override mactodevinfo) + +SAVEDEVSTRING="$DEVSTRING" + +UCI="$UCIBIN -c $UCICONFIG" +config_load $OVERRIDETABLE +DEVSTRING=$(config_foreach parse_override mactodevinfo) + +if [ -z "$DEVSTRING" ]; then + if [ -z "$SAVEDEVSTRING" ]; then + echo "$MAC | $OUIOWNER | unknown | unknown | unknown" + else + echo "$SAVEDEVSTRING" + fi +else + echo "$DEVSTRING" +fi + +rm -f $UCISTATE diff --git a/net/mac-to-devinfo/files/macdevdb b/net/mac-to-devinfo/files/macdevdb new file mode 100644 index 00000000000000..8bb88735946f60 --- /dev/null +++ b/net/mac-to-devinfo/files/macdevdb @@ -0,0 +1,8 @@ + +config 'mactodevinfo' + option 'maclow' '00:19:15:00:00:00' + option 'machigh' '00:19:15:ff:ff:ff' + option 'vendor' 'Vertical Communications' + option 'devtype' 'SIP devices' + option 'model' 'varies' + diff --git a/net/mac-to-devinfo/files/mactodevinfo b/net/mac-to-devinfo/files/mactodevinfo new file mode 100644 index 00000000000000..9cd0e5e60cdacd --- /dev/null +++ b/net/mac-to-devinfo/files/mactodevinfo @@ -0,0 +1,2 @@ +package mactodevinfo + diff --git a/net/mac-to-devinfo/files/netdiscover-to-devinfo b/net/mac-to-devinfo/files/netdiscover-to-devinfo new file mode 100644 index 00000000000000..c460dc1bfa2ad2 --- /dev/null +++ b/net/mac-to-devinfo/files/netdiscover-to-devinfo @@ -0,0 +1,67 @@ +#!/bin/sh +# netdiscover-to-devinfo - netdiscover to MAC IEEE and custom information +# Copyright (C) 2009 Daniel Dickinson + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +MACTODEV=mac-to-devinfo + +if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then + echo "Usage: netdiscover-to-devinfo IP-range Interface Timeout [-r repeats] [-s sleep_between_arp_requests]" + exit 1 +fi + +prep-devinfo +IFS=' +' + +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)" + IFS=' +' +done + +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 00000000000000..11a7e416e2f81c --- /dev/null +++ b/net/mac-to-devinfo/files/netsmap-to-devinfo @@ -0,0 +1,156 @@ +#!/bin/sh +# netsmap-to-devinfo - netdisovered then smap'ed IP addresses to MAC IEEE +# and custom information +# Copyright (C) 2009 Daniel Dickinson + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +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 Date: Sat, 21 Jun 2014 14:15:51 -0400 Subject: [PATCH 2/2] mac-to-devinfo: identify locally administered addresses Signed-off-by: Forest Crossman --- net/mac-to-devinfo/files/mac-to-devinfo | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/mac-to-devinfo/files/mac-to-devinfo b/net/mac-to-devinfo/files/mac-to-devinfo index cce253a94cd478..145bedda9b9f4a 100644 --- a/net/mac-to-devinfo/files/mac-to-devinfo +++ b/net/mac-to-devinfo/files/mac-to-devinfo @@ -127,6 +127,13 @@ if [ ! -r "$OUIFILE" ] || [ ! -r "$IABFILE" ]; then fi OUI="$(echo $MAC | cut -f1-3 -d: | sed -e 's/:/-/g' | tr abcdef ABCDEF )" +HIGHBYTE="$(echo $OUI | cut -f1 -d- )" + +if [[ $(($((0x$HIGHBYTE)) & $((0x2)))) != 0 ]]; then + LOCALMAC="(Locally Administered)" + NEWHIGHBYTE="$(printf "%X" $(( $((0x$HIGHBYTE)) & $(( ~$((0x2)) )) )) )" + OUI="$NEWHIGHBYTE-$(echo $OUI | cut -f2-3 -d- )" +fi OUIOWNER="$(cat $OUIFILE | grep $OUI | tr -s '\t' | cut -f2- -d"$(printf '\t')" )" @@ -168,6 +175,10 @@ if [ -z "$OUIOWNER" ] || [ "$OUIOWNER" = "IEEE REGISTRATION AUTHORITY" ]; then fi fi +if [ -n "$OUIOWNER" ] && [ -n "$LOCALMAC" ]; then + OUIOWNER="$OUIOWNER $LOCALMAC" +fi + if [ -z "$OUIOWNER" ]; then OUIOWNER="Unknown Organization" fi