使用tcpdump 对nginx的access.log 非400的ip进行自动抓包
#抓取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进行自动抓包的更多相关文章
- Nginx 的 access log 如何以 json 形式记录?
Nginx 的 access log 默认是以空格分隔的字符串形式记录的,格式如下 log_format proxy '[$time_local] $remote_addr ' '$protocol ...
- nginx的access.log文件详解
事实证明,日志文件真的是很重要很重要的.能够帮助我们快速的定位问题,并且知道用户访问的状态,浏览器,Ip,接口地址等,简直可怕.. 一.nginx的access.log(1)对博主而言,日志文件存放在 ...
- Nginx修改access.log日志时间格式
一.修改原因 因为要获取nginx访问信息,作为开发的数据使用,但是nginx的access.log文件中的默认的时间格式是这样的: [02/Nov/2017:20:48:25 +0800] 而要求的 ...
- 在nginx日志access log可以记录POST请求的参数值
1) 在nginx日志access log可以记录POST请求的参数值 实现程度:日志中可以显示POST请求所提交的参数值 问题: 日志中文显示十六进制(在配置文件中配置中文也无效) 没有对 ...
- shell定时统计Nginx下access.log的PV并发送给API保存到数据库
1,统计PV和IP 统计当天的PV(Page View) cat access.log | sed -n /`date "+%d\/%b\/%Y"`/p |wc -l 统计某一天的 ...
- nginx的access.log 和 error.log
nginx 常用的配置文件有两种: access.log 和 error.log access.log 的作用是 记录用户所有的访问请求,不论状态码,包括200 ,404,500等请求,404,500 ...
- 利用logrotate切割nginx的access.log日志
一.新建一个nginx的logrotate配置文件 /var/log/nginx/access.log { daily rotate compress delaycompress missingok ...
- nginx的access log按小时生成
1.在server或location段进行配置 if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})&q ...
- tcpdump指定IP和端口抓包
如下指定抓www.baidu.com 并且80端口的包 保存到test.cap 可以在Windows下面用wireshark打开 tcpdump 'port 80 and host www.baidu ...
随机推荐
- react-native 学习(二)
上一节讲到了 react-native的开发环境的配置,,这一节我门具体讲讲怎么看样式,怎么调试 看样式的话 有一个 神奇 react-native-developer tools(个人推荐,可选择性 ...
- glibc-2.23_int_free_流程浅析
- java基础05 选择结构
选择结构 public class Demo01Change { public static void main(String[] args) { /** * 实现等量的转换 */ int a = 5 ...
- js 获取Array数组 最大值 最小值
https://stackoverflow.com/questions/1669190/find-the-min-max-element-of-an-array-in-javascript // 错误 ...
- wait_event族函数浅析
2017-06-03 周末闲暇无事,聊聊内核中的wait_event*类函数的具体实现,等待事件必定涉及到某个条件,而这些函数的区别主要是等待后唤醒的方式……直奔主题,上源码 wait_event_i ...
- struts2之Action获取请求参数与web元素
文章思路清晰 http://blog.csdn.net/zeqblog/article/details/8665052
- (0.1)windows下的mysql配置使用步骤
目录 1.基于windows平台的mysql项目场景 2.mysql数据库运行环境准备 3.下载mysql 4.通过Installer方式(即msi方式)安装mysql 5.卸载mysql ————— ...
- linux下编写简单的守护进程
搭建linux服务器的时候,需要写一个简单的守护进程来监控服务的运行情况,shell脚本如下: #!/bin/sh function daemon() { while true do server=` ...
- Spring第八发—自动装配及让Spring自动扫描和管理Bean
依赖注入–自动装配依赖对象(了解即可) 对于自动装配,大家了解一下就可以了,实在不推荐大家使用.例子: byName:按名称装配,可以根据属性的名称,在容器中寻找跟该属性名相同的bean,如果没有找到 ...
- UVA10905: Children's Game(排序)
题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68990#problem/A 题目需求:,给n个数字,将它们重新排序得到一个最大的数 ...