Advertisement
rg443

fping log to tsv

Jun 13th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. if (sizeof($argv) > 1) {$q=$argv[1];} else {$q=null;print('filename required');exit(1);}
  4.  
  5. $re = '/^(\d+\/\d+\/\d+ \d+:\d+:\d+)\.\d+ : Reply\[\d+\] from ([0-9.]+): bytes=\d+ time=(\d+\.\d+) ms TTL=(\d+)/mi';
  6. ini_set('memory_limit','512M');
  7.  
  8. $output=file_get_contents($q);
  9. print (strlen ($output));
  10. if (!$output) {
  11.     print ('cant read ' . $q .'!');
  12.     exit();
  13. }
  14.  
  15.  
  16. preg_match_all($re, $output, $matches,PREG_SET_ORDER);
  17.  
  18. $file = fopen("c:/rgr/pinglog2-".date("Ymd").".txt", "a");
  19. $i=0;
  20. foreach ($matches as $val) {
  21.      $i=$i+1;
  22.      echo implode(array_slice ($val,1),"\t")."\n";
  23.      fwrite($file,implode(array_slice ($val,1),"\t")."\n");
  24.  
  25. }
  26. fclose($file);
  27.  
  28. print ($i);
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement