3 // Create or Update the vendor table in Management DB.
\r
4 // The table is used in opengatemchk
\r
6 // At installation, run to create vendor table
\r
8 // After installation, run periodically to update vendor table.
\r
11 //connect to Management DB (* set proper parameters *)
\r
12 $link = mysql_connect("localhost", "root", "");
\r
13 if (!$link) die('Cannot connect to DB.'.mysql_error());
\r
15 // select opengatem database
\r
16 $db_selected = mysql_select_db('opengatem', $link);
\r
17 if (!$db_selected) die('Cannot select DB.'.mysql_error());
\r
19 // create table if not exists
\r
20 $sql = "CREATE TABLE IF NOT EXISTS nicvendors(oui CHAR(8), org TINYTEXT)";
\r
23 // connect to oui list in IEEE site
\r
24 $fp = fopen("http://standards.ieee.org/develop/regauth/oui/oui.txt", "r");
\r
25 if(!$fp) die('Cannot connect to IEEE site. Check network connection');
\r
27 // scan the download list
\r
28 while (!feof($fp)) {
\r
33 // columns 0-7 may be oui
\r
34 $oui = substr($line, 0, 8);
\r
36 //if $oui is not "**-**-**", skip the line
\r
37 if(preg_match('/^[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}$/',$oui)!=1)continue;
\r
39 // reformat $oui from "01-56-AB" to "01:56:ab"
\r
40 $oui = str_replace("-",":",$oui);
\r
41 $oui = strtolower($oui);
\r
43 // column 16- should be vendor name (trim CR code)
\r
44 $org = substr($line, 16);
\r
46 // remove CR code and quotation code
\r
47 $org = str_replace(array("\r\n","\n","\r"), "", $org);
\r
48 $org = str_replace("\"", "", $org);
\r
49 $org = str_replace("\t", "", $org);
\r
53 'REPLACE INTO nicvendors (oui,org) VALUES( "%s", "%s")',
\r
58 print $oui." ".$org."<br>\n";
\r