#抓取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. UVA12470—Tribonacci (类似斐波那契,简单题)

    题目链接:https://vjudge.net/problem/UVA-12470 题目意思:我们都知道斐波那契数列F[i]=F[i-1]+F[i-2],现在我们要算这样的一个式子T[i]=T[i-1 ...

  2. ArcGIS Data Store 初体验

    1. 什么是ArcGIS Data Store? ArcGIS Data Store 是10.3新推出的一个组件,从官方对其定位来说,该组件是用来优化发布托管服务到portal for ArcGIS的 ...

  3. Python3量化技术常用插件

    1. 确定自己的系统为64位版本 2. 下载安装Python3 64位版本 如果要使用zipline,建议使用python3.5.另外发现很多东西要求的也是3.5. 主页地址: https://www ...

  4. 剑指Offer——求1+2+3+...+n

    题目描述: 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 分析: 递归实现. 代码: class So ...

  5. 软中断和tasklet介绍

    今天看了下tasklet,重点分析了其和软中断的关系,特此记录 关于软中断,在之前的中断文章中已经有所介绍,这里就不多说了,只是说明下,系统中默认支持32种软中断,而实际上系统定义的软中断仅有以下几种 ...

  6. centos7配置IP地址

    有关于centos7获取IP地址的方法主要有两种,1:动态获取ip:2:设置静态IP地址 在配置网络之前我们先要知道centos的网卡名称是什么,centos7不再使用ifconfig命令,可通过命令 ...

  7. @JsonFormat与@DateTimeFormat注解的使用

    背景:从数据库获取时间传到前端进行展示的时候,我们有时候可能无法得到一个满意的时间格式的时间日期,在数据库中显示的是正确的时间格式,获取出来却变成了很丑的时间戳,@JsonFormat注解很好的解决了 ...

  8. linux内核介绍

    linux系统可以分为:包括用户空间和内核空间两个部分. 现代cpu通常实现了不同的工作模式,以ARM为例,实现了7种工作模式: 用户模式.快速中断.外部中断.管理模式.数据访问中止.系统模式.未定义 ...

  9. POJ3281:Dining(dinic+拆点)

    题目链接:http://poj.org/problem?id=3281 PS:刷够网络流了,先这样吧,之后再刷,慢慢补. 题意:有F种食物,D种饮料,N头奶牛,只能吃某种食物和饮料(而且只能吃特定的一 ...

  10. Get a better look at the 2014 Nike Hyperrev

    There's a couple of Nike Hyperrev For Sale Delay climax frames lead that will list for this calendar ...