Advertisement
Joker0day

gov_mil_Log.php

Jul 22nd, 2018
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. set_time_limit('18000');
  5.  
  6. //Unix required (grep / logresolve must be present on system)
  7.  
  8. $logresolve_path = '/usr/sbin/logresolve'; //find / -name logresolve
  9. $log_path = '../logs/access_log'; //location of Apache raw log file
  10.  
  11. system($logresolve_path.' < '.$log_path.' > access_log_resolved.log');
  12. system("grep -e '\\.gov\\|\\.mil' access_log_resolved.log > access_log_resolved_special.log")
  13.  
  14. $hostnames = array();
  15. $lines=file('access_log_resolved_special.log');
  16. for($i=0;$i<count($lines);$i++){
  17. list($hostname) = split(' ', $lines[$i], 2);
  18.  
  19. if (preg_match("/\.mil$|\.gov$|\.gov\.[a-z]+$/", $hostname)) {
  20.  
  21. list($hn1, $hostnamep) = explode('.', $hostname, 2);
  22.  
  23. if (preg_match("/^gov\.[a-z]+$/", $hostnamep)) {
  24. $hostnamep = $hostname;
  25. } else {
  26. $hostnamep = '.'.$hostnamep;
  27. //$toadd = strlen($hn1);
  28. //$hostnamep = str_repeat('*', $toadd) . '.' . $hostnamep;
  29. }
  30.  
  31. $hostnames[] = $hostnamep;
  32. }
  33. }
  34.  
  35. $hostnames_unique = array_unique($hostnames);
  36.  
  37. $hostnameslist = '';
  38. foreach ($hostnames_unique as $hostname) {
  39. $hostnameslist .= $hostname."\r\n";
  40. }
  41.  
  42. echo $hostnameslist;
  43.  
  44. $file = fopen("specialhitslist.log","w");
  45. flock ($file,2);
  46. fwrite($file,$hostnameslist);
  47. fclose($file);
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement