gen-oui.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. //download url:
  3. // https://standards-oui.ieee.org/oui/oui.txt
  4. // https://github.com/vcrhonek/hwdata/blob/master/oui.txt
  5. $oui_download_url = 'https://standards-oui.ieee.org/oui/oui.txt';
  6. if (!file_exists('oui.original')) {
  7. echo "[+] Downloading updated oui.txt...\n";
  8. $remote_file = file_get_contents($oui_download_url);
  9. file_put_contents('oui.original', $remote_file);
  10. }
  11. echo "[+] Processing oui.txt...\n";
  12. @unlink('oui.txt');
  13. $flag = '(base 16)';
  14. $total = 0;
  15. $output = [];
  16. $index = [];
  17. foreach (file('oui.original') as $line) {
  18. if (strpos($line, $flag) !== false){
  19. $parts = explode($flag, $line);
  20. $id = mb_strtoupper(trim($parts[0]));
  21. // repeat : 0001C8
  22. // chars : 48BCA6, 489153, 4898CA
  23. if (!in_array($id, $index, true)) {
  24. $total++;
  25. $index[] = $id;
  26. $text = ucwords(mb_strtolower($parts[1]));
  27. //$text = preg_replace('/[[:^print:]]/', '', $text);
  28. //$text = filter_var($text, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
  29. //$text = preg_replace('/\s+/u', ' ', $text);
  30. $text = str_replace(['.', ','], '', $text);
  31. $output[] = $id . trim($text);
  32. }
  33. }
  34. }
  35. sort($output);
  36. $output[] = '';
  37. file_put_contents('oui.txt', implode("\n", $output));
  38. unlink('oui.original');
  39. echo "[+] Processing complete!\n";
  40. echo "[*] File: oui.txt - Lines: {$total}\n";