Create and manage information on MAC address OUIs
(Organizationally Unique Identifiers). This is the manufacturer's code in the MAC address.
This commit is contained in:
parent
2b6a35f7cd
commit
aa2a3bfd48
52
contrib/mac/createoui
Executable file
52
contrib/mac/createoui
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Utility to create manufacturer's oui table
|
||||||
|
# OUI is "Organizationally Unique Identifier" assigned by IEEE.
|
||||||
|
# There are currently three duplicate listings, so we can not enforce
|
||||||
|
# uniqueness in the OUI field.
|
||||||
|
# - thomas 2000-08-21
|
||||||
|
|
||||||
|
args=
|
||||||
|
update=0
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
--update)
|
||||||
|
update=1
|
||||||
|
;;
|
||||||
|
--noupdate)
|
||||||
|
update=0
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
echo "Usage: $0 --[no]update dbname"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
args="$args $1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
psql -e $args <<EOF
|
||||||
|
-- Table containing OUI portions of MAC address and manufacturer's name
|
||||||
|
create table macoui (
|
||||||
|
addr macaddr not null,
|
||||||
|
name text not null
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create an index to help lookups
|
||||||
|
create index macoui_idx on macoui (addr);
|
||||||
|
|
||||||
|
-- Function to return manufacturer's name given MAC address
|
||||||
|
create function manuf (macaddr)
|
||||||
|
returns text as '
|
||||||
|
select name from macoui m where trunc(\$1) = m.addr;
|
||||||
|
' language 'SQL';
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $update -gt 0 ]; then
|
||||||
|
updateoui $args
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit
|
25
contrib/mac/dropoui
Executable file
25
contrib/mac/dropoui
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Utility to remove manufacturer's oui table
|
||||||
|
|
||||||
|
args=
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
--help)
|
||||||
|
echo "Usage: $0 dbname"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
args="$args $1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
psql $args <<EOF
|
||||||
|
drop function manuf(macaddr);
|
||||||
|
drop table macoui;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
exit
|
53
contrib/mac/ouiparse.awk
Normal file
53
contrib/mac/ouiparse.awk
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
# $Id: ouiparse.awk,v 1.1 2000/08/23 06:02:23 thomas Exp $
|
||||||
|
#
|
||||||
|
# ouiparse.awk
|
||||||
|
# Author: Lawrence E. Rosenman <ler@lerctr.org>
|
||||||
|
# Original Date: 30 July 2000 (in this form).
|
||||||
|
# This AWK script takes the IEEE's oui.txt file and creates insert
|
||||||
|
# statements to populate a SQL table with the following attributes:
|
||||||
|
# create table oui (
|
||||||
|
# oui macaddr primary key,
|
||||||
|
# manufacturer text);
|
||||||
|
# the table name is set by setting the AWK variable TABLE
|
||||||
|
#
|
||||||
|
# we translate the character apostrophe (') to space inside the company name
|
||||||
|
# to avoid SQL errors.
|
||||||
|
#
|
||||||
|
# match ONLY lines that begin with 2 hex numbers, -, and another hex number
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
TABLE="macoui";
|
||||||
|
printf "DELETE FROM %s;",TABLE;
|
||||||
|
printf "BEGIN TRANSACTION;";
|
||||||
|
nrec=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
# if (nrec > 0)
|
||||||
|
printf "COMMIT TRANSACTION;";
|
||||||
|
}
|
||||||
|
|
||||||
|
/^[0-9a-fA-F][0-9a-fA-F]-[0-9a-fA-F]/ {
|
||||||
|
# if (nrec >= 100) {
|
||||||
|
# printf "COMMIT TRANSACTION;";
|
||||||
|
# printf "BEGIN TRANSACTION;";
|
||||||
|
# nrec=0;
|
||||||
|
# } else {
|
||||||
|
# nrec++;
|
||||||
|
# }
|
||||||
|
# Get the OUI
|
||||||
|
OUI=$1;
|
||||||
|
# Skip the (hex) tag to get to Company Name
|
||||||
|
Company=$3;
|
||||||
|
# make the OUI look like a macaddr
|
||||||
|
gsub("-",":",OUI);
|
||||||
|
OUI=OUI ":00:00:00"
|
||||||
|
# Pick up the rest of the company name
|
||||||
|
for (i=4;i<=NF;i++)
|
||||||
|
Company=Company " " $i;
|
||||||
|
# Modify any apostrophes (') to avoid grief below.
|
||||||
|
gsub("'","''",Company);
|
||||||
|
# Print out for the 'C' structure in mac.c
|
||||||
|
printf "INSERT INTO %s (addr, name) VALUES (trunc(macaddr \'%s\'),\'%s\');\n",
|
||||||
|
TABLE,OUI,Company;
|
||||||
|
}
|
34
contrib/mac/updateoui
Executable file
34
contrib/mac/updateoui
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
# Utility to create manufacturer's OUI table
|
||||||
|
|
||||||
|
args=
|
||||||
|
refresh=0
|
||||||
|
|
||||||
|
while [ $# -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
--refresh|--fetch|-r)
|
||||||
|
refresh=1
|
||||||
|
;;
|
||||||
|
--norefresh|--nofetch)
|
||||||
|
refresh=0
|
||||||
|
;;
|
||||||
|
--help)
|
||||||
|
echo "Usage: $0 --[no]refresh dbname"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
args="$args $1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $refresh -gt 0 ]; then
|
||||||
|
[ -e oui.txt ] && rm -rf oui.txt
|
||||||
|
wget -nd 'http://standards.ieee.org/regauth/oui/oui.txt'
|
||||||
|
fi
|
||||||
|
|
||||||
|
awk -f ouiparse.awk < oui.txt | psql -e $args
|
||||||
|
|
||||||
|
exit
|
Loading…
x
Reference in New Issue
Block a user