#抓取nginx access日志不是 400 的行,找出该ip ,并且启动抓包
#该脚本的执行要放在 crond 里面或者 while循环里面
################## #网卡名称
net_card=enp0s8
#最多抓取10条记录
cap_max_ip_num=1
#要抓取ip的在nginx里面的错误 #存放抓包的目录
cap_dir="/tmp/cap_dir/"
if [ ! -d "$cap_dir" ]; then
mkdir "$cap_dir"
fi #当前已经开始抓包的ip地址
cap_ip_history_file="$cap_dir/___tcp_dump_ip"
if [ ! -f "$cap_ip_history_file" ]; then
  touch "$cap_ip_history_file"
fi function mytcpdump()
{
ip=$1
tcpdump -i $net_card -w $cap_dir/file${ip}.cap host $1 &
} function begin_capture()
{
count_line=`wc -l $cap_ip_history_file | awk '{print $1}'`
if [ $count_line -ge $cap_max_ip_num ];then
echo " capture max limit !!"
exit 1
fi ip=`tail -1 access.log |awk '{if($(NF-4)==400) print $1}'`
echo "access the log is " $ip
if [ "$ip" != "" ]; then
grep_result=`grep "$ip" $cap_ip_history_file `
if [ "$grep_result" == "" ]; then
echo "begin tcp dump " $ip
echo `date` $ip >> $cap_ip_history_file
mytcpdump $ip
fi
fi
} function clean()
{
rm -rf $cap_dir
} case "$1" in
start)
begin_capture
;;
clean)
clean
;;
*)
echo $"Usage: $0 {start|clean}"
exit 1
esac

使用tcpdump 对nginx的access.log 非400的ip进行自动抓包的更多相关文章

  1. Nginx 的 access log 如何以 json 形式记录?

    Nginx 的 access log 默认是以空格分隔的字符串形式记录的,格式如下 log_format proxy '[$time_local] $remote_addr ' '$protocol ...

  2. nginx的access.log文件详解

    事实证明,日志文件真的是很重要很重要的.能够帮助我们快速的定位问题,并且知道用户访问的状态,浏览器,Ip,接口地址等,简直可怕.. 一.nginx的access.log(1)对博主而言,日志文件存放在 ...

  3. Nginx修改access.log日志时间格式

    一.修改原因 因为要获取nginx访问信息,作为开发的数据使用,但是nginx的access.log文件中的默认的时间格式是这样的: [02/Nov/2017:20:48:25 +0800] 而要求的 ...

  4. 在nginx日志access log可以记录POST请求的参数值

    1)      在nginx日志access log可以记录POST请求的参数值 实现程度:日志中可以显示POST请求所提交的参数值 问题: 日志中文显示十六进制(在配置文件中配置中文也无效) 没有对 ...

  5. shell定时统计Nginx下access.log的PV并发送给API保存到数据库

    1,统计PV和IP 统计当天的PV(Page View) cat access.log | sed -n /`date "+%d\/%b\/%Y"`/p |wc -l 统计某一天的 ...

  6. nginx的access.log 和 error.log

    nginx 常用的配置文件有两种: access.log 和 error.log access.log 的作用是 记录用户所有的访问请求,不论状态码,包括200 ,404,500等请求,404,500 ...

  7. 利用logrotate切割nginx的access.log日志

    一.新建一个nginx的logrotate配置文件 /var/log/nginx/access.log { daily rotate compress delaycompress missingok ...

  8. nginx的access log按小时生成

    1.在server或location段进行配置 if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})&q ...

  9. tcpdump指定IP和端口抓包

    如下指定抓www.baidu.com 并且80端口的包 保存到test.cap 可以在Windows下面用wireshark打开 tcpdump 'port 80 and host www.baidu ...

随机推荐

  1. Centos7.2yum安装时候出现db5错误的解决办法

    Centos7.2使用yum安装软件是出现如此错误提示 解决办法 删除 /var/lib/rpm文件夹下面所有以__db开头的文件

  2. Orchard 与 ABP架构比较 (aspnetboilerplate)

    前言:  ABP框架经常在一些.NET群中听群友提起,以前也浏览过官网,大致了解它是一个框架,直到今天本人才正式下载源码入门 ... 经过两个小时的ABP中文文档入门(感谢各位辛勤的翻译者) ,大致了 ...

  3. Windows中压缩版的MySQL的安装、配置

    本次笔记是根据mysql-8.0.13-winx64版本编写: 1.将下载的压缩包解压到自己想放的目录 2.右键计算机 -> 属性 -> 高级系统设置 -> 环境变量 -> 系 ...

  4. leetcode 去除单链表倒数第k个节点

    Given a linked list, remove the n-th node from the end of list and return its head. Example: Given l ...

  5. 【numpy】

    ndarray在某个维度上堆叠,np.stack() np.hstack() np.vstack() https://blog.csdn.net/csdn15698845876/article/det ...

  6. dict文档

    文档 class dict(object): """ dict() -> new empty dictionary 创建字典的方式有两种: 1.dic = {} 2 ...

  7. django组件之ContentType

    ContentTyep组件: 帮助我们关联所有数据库的表 帮助我们反向查询关联数据表中的所有策略信息 GenericForeignkey(帮助我们快速插入数据) GenericRelation(用于反 ...

  8. Java中的反射[转载]

    转自:https://blog.csdn.net/sinat_38259539/article/details/71799078#commentBox 1.什么是反射? 反射是通过一个类可以知道其中所 ...

  9. MongoDB的分布式部署

    一.分片的概念 分片(sharding)是指根据片键,将数据进行拆分,使其落在不同的机器上的过程.如此一来,不需要功能,配置等强大的机器,也能储存大数据量,处理更高的负载. 二.分片的原理和思想 Mo ...

  10. JavaScript和jQuery的学习

    还有12天就要回学校了,我的假期计划还能实现吗?在这12天里,需要把JavaScript和jQuery学完.我知道这两个技术对于前端网页开发非常重要.前期把HTML和CSS学完了,学的不是特别深,只是 ...