gor 流量錄製 && php 解析請求

 1. 安裝gor

https://github.com/buger/goreplay

下載後直接解壓縮即可使用

mac: 下載地址

linux: 下載地址

 2, 使用gor 監聽某接口,錄製流量

gor --input-raw :22771  --output-file origin_requests_%Y%m%d.log --output-file-append 

 

3,使用PHP 解析請求

保存的內容爲:

解析後的內容爲

 

<?php
$fp=fopen('./requests_0.log',"r");
$need='';
$line=0;
while(!feof($fp)){
    $content=fgets($fp);
    if(urlencode($content)=='%F0%9F%90%B5%F0%9F%99%88%F0%9F%99%89%0A'){
		$need=$temp;
        $temp='';
    }else{
       $content=trim($content);
        if(strpos($content,":")==false){
             $arr=explode(" ",$content);
		     if($line==0){
			     $temp=$arr[2]."||";
			 }
			 if($line==1){
                 $temp.=$arr[0]."||".$arr[1]."||";
			 }

        }else{
            [$header,$value]=explode(':',$content);
            $temp.=$content."@@";
        }
    }
	$line++;
}
echo $need;

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章