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