Guest User

Untitled

a guest
Oct 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. 127.0.0.3 familiya-in
  2.  
  3. 00:25:00:0F:00:1A 127.0.0.3
  4.  
  5. 192.168.10.2 00:25:00:0F:00:1A
  6.  
  7. familiya-in 00:25:00:0F:00:1A 192.168.10.2
  8.  
  9. function readData($name) {
  10. $res = [];
  11. $handle = fopen($name, "r");
  12. if ($handle) {
  13. while (($str = fgets($handle) !== false) {
  14. $parsed = explode(' ', $str);
  15. $res[$parsed[1]] = $parsed[0];
  16. }
  17. fclose($handle);
  18. }
  19. return res;
  20. }
  21.  
  22. $mac_list = readData('file2');
  23. $ip_list = readData('file3');
  24. $data = [];
  25. $handle = fopen('file1', "r");
  26. if ($handle) {
  27. while (($str = fgets($handle) !== false) {
  28. $parsed = explode(' ', $str);
  29. $name = $parsed[1];
  30. $mac = $mac_list[$name];
  31. $ip = $ip_list[$mac];
  32. printf('%s %s %s', $name, $mac, $ip);
  33. }
  34. fclose($handle);
  35. }
  36.  
  37. function getAndExplode($fileName, $key = 0) {
  38. $contents = file_get_contents($fileName);
  39. $exploded = explode(" ", $contents);
  40. return $exploded[$key];
  41. }
  42.  
  43. $string = getAndExplode("file1.txt", 1)
  44. . " " . getAndExplode("file2.txt")
  45. . " " . getAndExplode("file3.txt");
  46.  
  47. echo $string;
  48.  
  49. // familiya-in 00:25:00:0F:00:1A 192.168.10.2
Add Comment
Please, Sign In to add comment