updated on Sat Jan 21 08:01:15 UTC 2012
[aur-mirror.git] / netdiscover-debian / update-oui-database.sh
blob4af38bf5f36732ce722b7407a5d9efb45fed852c
1 #!/bin/bash
3 # Script for generation "oui.h" file (netdiscover program at
4 # http://nixgeneration.com/~jaime/netdiscover/
6 # Obtain data from internet source at:
7 # lynx -source http://standards.ieee.org/regauth/oui/oui.txt >oui.txt
9 # Syntax: oui.txt2oui.h_netdiscover
11 # Script generate src/oui.h file.
13 # 16-May-2009 Frantisek Hanzlik <franta@hanzlici.cz> (Original author)
14 # 07-Jun-2001 Larry Reznick <lreznick@rezfam.com> (fixes & code clean)
15 #**********************************************************************
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 3 of the License, or
20 # (at your option) any later version.
23 JA=${0##*/}
24 DATE=$(date +'%Y%m%d')
25 ORIGF=oui.txt
26 DSTD=src
27 DSTF=oui.h
28 URL="http://standards.ieee.org/regauth/oui/oui.txt"
29 TMPF=$ORIGF-$DATE
30 AWK="gawk"
31 #AWK="mawk"
32 #AWK="awk"
34 [ -d "$DSTD" ] || { echo "$JA: Destdir \"$DSTD\" not exist!"; exit 1; }
35 #if ! [ -f "$TMPF" -a -s "$TMPF" ]; then
36 # echo "Trying download \"$ORIGF\" with lynx..."
37 # if ! lynx -source $URL >"$TMPF"; then
38 # echo "Trying download \"$ORIGF\" with elinks..."
39 # if ! elinks -source $URL >"$TMPF"; then
40 # echo "Trying download \"$ORIGF\" with wget..."
41 # if ! wget --quiet --output-document="$TMPF" $URL; then
42 # echo "$JA: Cann't obtain \"$URL\"!"
43 # exit 1
44 # fi
45 # fi
46 # fi
47 #else
48 # echo "\"$TMPF\" already exist, skipping download..."
49 #fi
50 if ! [ -f "$TMPF" -a -s "$TMPF" ]; then
51 echo -n "Trying download \"$ORIGF\" with lynx..."
52 if [[ -x /usr/bin/lynx ]]; then
53 lynx -source $URL >"$TMPF"
54 else
55 echo -n " with elinks..."
56 if [[ -x /usr/bin/elinks ]]; then
57 elinks -source $URL >"$TMPF"
58 else
59 echo " with wget..."
60 if [[ -x /usr/bin/wget ]]; then
61 wget --quiet --output-document="$TMPF" $URL
62 else
63 echo "$JA: Can't obtain \"$URL\"!"
64 exit 1
68 else
69 echo -n "\"$TMPF\" already exist, skipping download..."
71 echo ""
73 echo "Process oui.txt (\"$TMPF\")..."
75 # if RS is null string, then records are separated by blank lines...
76 # but this isn't true in oui.txt
78 LANG=C $AWK --re-interval --assign URL="$URL" '
79 BEGIN {
80 RS = "\n([[:blank:]]*\n)+";
81 FS = "\n";
82 MI = "";
83 NN = 0;
84 printf( \
85 "/*\n" \
86 " * Organizationally Unique Identifier list at date %s\n" \
87 " * Automatically generated from %s\n" \
88 " * For Netdiscover by Jaime Penalba\n" \
89 " *\n" \
90 " */\n" \
91 "\n" \
92 "struct oui {\n" \
93 " char *prefix; /* 24 bit global prefix */\n" \
94 " char *vendor; /* Vendor id string */\n" \
95 "};\n" \
96 "\n" \
97 "struct oui oui_table[] = {\n", strftime("%d-%b-%Y"), URL);
100 (/[[:xdigit:]]{6}/) {
101 N1 = split($1,A1,/\t+/);
102 N2 = split($2,A2,/\t+/);
103 N3 = split(A2[1],PN,/ +/);
104 # printf("%i,%i,%i>%s<>%s<>%s< $1=%s<, $2=%s<, $3=%s<.\n",N1,N2,N3,PN[1],A1[2],A2[2],$1,$2,$3);
105 # V1 = gensub(/^[[:punct:]]+/,"",1,A1[2]);
106 # V2 = gensub(/^[[:punct:]]+/,"",1,A2[2]);
107 V1 = gensub(/^[[:blank:]]+/,"",1,A1[2]);
108 V2 = gensub(/^[[:blank:]]+/,"",1,A2[2]);
109 V0 = V2;
110 if (V0 ~ /^[[:blank:]]*$/) {
111 V0 = V1;
113 V = gensub(/\"/,"\\\\\"","g",V0);
114 if (MI != "")
115 printf(" { \"%s\", \"%s\" },\n", MI, MV);
116 MI = PN[1];
117 MV = V;
118 NN++;
121 END {
122 printf( \
123 " { \"%s\", \"%s\" },\n" \
124 " { NULL, NULL }\n" \
125 "};\n" \
126 "\n" \
127 "// Total %i items.\n", MI, MV, NN);
128 }' <"$TMPF" >"$DSTD/$DSTF"
130 if [ $? -ne 0 ]; then
131 echo "$JA: $TMPF parsing error !"
132 exit 1
133 else
134 echo "All OK"
135 ls -oh oui.txt-* src/oui.h