./c0de/php/govmilhits_php.txt

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

Back