Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions net/mac-to-devinfo/Makefile
Original file line number Diff line number Diff line change
@@ -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 <openwrt@cshore.neomailbox.net>
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))
26 changes: 26 additions & 0 deletions net/mac-to-devinfo/files/clean-devinfo
Original file line number Diff line number Diff line change
@@ -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
122 changes: 122 additions & 0 deletions net/mac-to-devinfo/files/devinfo-functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/sh
# Shell script compatibility wrappers for /sbin/uci
#
# Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
# 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"
}

80 changes: 80 additions & 0 deletions net/mac-to-devinfo/files/ip-to-devinfo
Original file line number Diff line number Diff line change
@@ -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


Loading