Project

General

Profile

Feature #3882 » update_oui.sh

Jim Pingle, 09/22/2014 09:59 AM

 
1
#!/bin/sh
2
#
3
# Run me to update the file in the package repo.
4
#
5
OUI_URL=http://standards.ieee.org/develop/regauth/oui/oui.txt
6
OUI_FILE=/usr/local/share/nmap/nmap-mac-prefixes
7
#OUI_FILE=nmap-mac-prefixes
8
TEMP_FILE=/tmp/oui-prefixes.txt
9

    
10
# Prepare file
11
if [ -f ${TEMP_FILE} ]; then
12
	rm -f ${TEMP_FILE}
13
fi
14

    
15
echo "# Raw data obtained from ${OUI_URL}"  > ${TEMP_FILE}
16
echo "# Unregistered OUIs at the end are from NMAP - http://nmap.org/" >> ${TEMP_FILE}
17

    
18
/usr/bin/fetch -qo - ${OUI_URL} | /usr/bin/grep "base 16" | /usr/bin/sed -r 's/[[:blank:]]+/ /g' | /usr/bin/cut -c2-7,18- >> ${TEMP_FILE}
19

    
20
# Make sure it's valid
21
# Line count should be over 17,000
22
OUTPUT_WORD_COUNT=`/usr/bin/wc -l ${TEMP_FILE} | /usr/bin/awk '{print $1;}'`
23

    
24
# Spot check one line should contain  "589CFC.*FreeBSD"
25
OUTPUT_CHECK=`/usr/bin/grep -ci "589CFC.*FreeBSD" ${TEMP_FILE}`
26

    
27
if [ ${OUTPUT_WORD_COUNT} -gt 17000 ] && [ ${OUTPUT_CHECK} = 1 ]; then
28
	# Stuff in some missing prefixes
29
	echo "00FFD1 Cooperative Linux virtual NIC" >> ${TEMP_FILE}
30
	echo "2C7AFE IEE&E Black ops" >> ${TEMP_FILE}
31
	echo "525400 QEMU Virtual NIC" >> ${TEMP_FILE}
32
	echo "B0C420 Bochs Virtual NIC" >> ${TEMP_FILE}
33
	echo "DEADCA PearPC Virtual NIC" >> ${TEMP_FILE}
34
	echo "F0FB56 Apple" >> ${TEMP_FILE}
35
	if [ -f ${OUI_FILE} ]; then
36
		rm -f ${OUI_FILE}
37
	fi
38
	mkdir -p `/usr/bin/dirname ${OUI_FILE}`
39
	mv ${TEMP_FILE} ${OUI_FILE}
40
fi
(1-1/2)