当前位置:网站首页>38 lines of PHP code free import database analysis Linux access log
38 lines of PHP code free import database analysis Linux access log
2022-07-25 04:51:00 【YUJIANYUE】
Used to analyze linux Exception of log file IP, For example, high frequency visits to spiders , High frequency vulnerability detection URL Of IP
The system will press IP The number of visits is sorted , You can analyze their behavior hundreds of times .
such as [email protected] More times ,URL Most of them are not your common paths , The IP That is to scan website vulnerabilities .
such as IP The number of many ,UA Have a website address or include spider/bot/crawler Wait is a spider ,python-requests Artificial wild spider
Performance reference :1 nucleus 1GBwin Server Analysis 76.5852MB/404101 Logs @ Time consuming [email protected] Memory 20,795.22KB
<?php
header("Content-type:text/html;charset=utf-8");
ob_implicit_flush();
set_time_limit(9000); // Suggest to modify PHP The timeout of the corresponding version 100 For larger values such as 9000
echo "<style>table{border-top:2px solid #0180CF; margin:0 auto;font-size:12px;width:99%;}
table td{min-width:66px;border-bottom:1px solid #a2c6d3;padding:5px 0px;word-wrap:break-word;word-break:break-all;}
table tr:nth-child(even){background: #FCFCFC;}
.tt{background:#e5f2fa;line-height:18px;FONT-SIZE:12px;font-weight:600;}</style>";
function readcsv($filex){
$handle = fopen($filex, "r");
while ($data = fgetcsv($handle,0," ")) {
yield $data; //php 5.5+
}
fclose($handle);
}
$start = microtime(true);
$mstar = memory_get_usage();
$biaoge = "{$biaoge}_loge";
$filex= "./***.log"; // modify linux Log file path
echo "<h1> Statistics IP Traffic volume ($filex)</h1> Used to analyze exceptions IP, For example, high frequency visits to spiders , High frequency vulnerability detection URL Of IP";
$ii=0; $iz=0; $sqla = array(); $sqlb = array();
foreach (readcsv($filex) as $key => $kar) {
$ii++; $ipx = $kar[0]."@".$kar[6]; $kall = $ii."\t".join("\t",$kar);
if(!$sqla[$ipx]){ $sqla[$ipx] = 1; $sqlb[$ipx] = $kall; }else{ $sqla[$ipx] += 1;}
}
arsort($sqla);
echo "<table>";
echo "<tr class='tt'><td width='80'>[email protected] state </td><td width='40'> frequency </td><td> sample </td></tr>";
foreach ($sqla as $tip => $tcs) {
echo "<tr><td>$tip</td><td>$tcs</td><td>".$sqlb[$tip]."</td></tr>";
}
echo "</table>";
$sstop = microtime(true); $mstop = memory_get_usage();
$fsize = number_format(filesize($filex)/1024/1024,2);
$us = "<p> analysis {$fsize}MB/{$ii} Logs @ Time consuming ".number_format($sstop-$start, 2);
$us .= "@ Memory consumption ".number_format(($mstop-$mstar)/1024, 2)."KB";
$us .= "/ total ".number_format(memory_get_peak_usage()/1024,2).'KB</p>';
echo $us;
边栏推荐
- MySQL -- index and transaction isolation level
- Deep understanding of pod
- Learn to use PHP to get the URL address link after resetting
- Implementation of recommendation system collaborative filtering in spark
- [detailed tutorial] a thorough article on mongodb aggregation query
- Actual combat | record an attack and defense drill management
- Detailed explanation of security authentication of mongodb
- @Summary of ResponseBody annotation
- [c language] custom type (structure ~ enumeration ~ Union)
- 实战|记一次攻防演练打点
猜你喜欢

ThreadLocal Kills 11 consecutive questions

Web: compiling big refactoring from 10 to 1

教你如何定位不合理的SQL?并优化之

5年经验的大厂测试/开发程序员,怎样突破技术瓶颈?大厂通病......

Androd releases jitpack open source project (gradle7.2)

The 6th "Blue Hat Cup" National College Students' Cyber Security Skills Competition writeup

开源之夏专访|“00 后” PMC member 白泽平

Wechat official account all article download links to get

Basic knowledge of scratch crawler framework

Ownership in rust -- introduction of rust language Xiaobai 11
随机推荐
Data link layer protocol -- Ethernet protocol
中创算力荣获「2022年科技型中小企业」认定
教你如何定位不合理的SQL?并优化之
Metinfo function public function getcity() error: XXX function no permission load!!!
If the development of the metauniverse still follows the development logic of the Internet, and its end point also follows
Compile ue5.0
# 1. Excel的IF函数
Pyg builds GCN to realize link prediction
How to get the database creation time?
Information System Project Manager --- Chapter IX examination questions of project human resource management over the years
MCU experiment record
2022-7-15 summary
AUTOSAR from getting started to mastering 100 lectures (105) - protection mechanism of AUTOSAR timing for functional safety
Unity3d learning note 9 - loading textures
What is behind the development of science and technology now is the advent of the era of the meta universe
阿亚的角度思考
Kubesphere 3.3.0 offline installation tutorial
Get the parameters of the browser address bar
Detailed explanation of security authentication of mongodb
If you don't know these 20 classic redis interview questions, don't go to the interview!