3 /************************************************************/
4 // Create or Update the vendor table in Management DB.
5 // The table is used in opengatemchk
7 // At installation, run to create vendor table
8 // After installation, run periodically to update vendor table.
10 // the database connection parameters might be modified.
11 // As this script should be used only by the administrators,
12 // it should be protected by some access control method.
13 /************************************************************/
15 //connect to Management DB (* set proper parameters *)
16 $link = mysqli_connect("localhost", "root", "");
17 if (!$link) die('Cannot connect to DB.'.mysqli_error());
19 // select opengatem database
20 $db_selected = mysqli_select_db($link, 'opengatem');
21 if (!$db_selected) die('Cannot select DB.'.mysqli_error());
23 // create table if not exists
24 $sql = "CREATE TABLE IF NOT EXISTS nicvendors(oui CHAR(8), org TINYTEXT)";
25 mysqli_query($link, $sql);
27 // open oui list in IEEE site
28 // $fp = fopen("http://standards.ieee.org/develop/regauth/oui/oui.txt", "r");
29 $fp = fopen("./oui.txt", "r");
30 if(!$fp) die('Cannot connect to IEEE data');
32 // scan the download list
38 // get oui(MAC-left-3bytes) and org(company name) from header line
39 // such as "AB-CD-EF (hex) Foo-bar company"
40 $pattern='/([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})\s*\(hex\)\s*(.*)$/';
41 if(preg_match($pattern, $line, $matches)!=1) continue;
45 // replace AB-CD-EF to ab:cd:ef
46 $oui = str_replace("-",":",$oui);
47 $oui = strtolower($oui);
49 // remove quotation and tab code
50 $org = str_replace("\"", "", $org);
51 $org = str_replace("\t", "", $org);
55 'REPLACE INTO nicvendors (oui,org) VALUES( "%s", "%s")',
57 mysqli_query($link, $sql);
60 print $oui." ".$org."<br>\n";