第一部分,
1,查看TCP连接状态

netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
netstat -ant|awk '/ip:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -n
netstat -ant|awk '/:80/{split($5,ip,":");++S[ip[1]]}END{for (a in S) print S[a],a}' |sort -rn|head -n 10
awk 'BEGIN{printf ("http_code\tcount_num\n")}{COUNT[$10]++}END{for (a in COUNT) printf a"\t\t"COUNT[a]"\n"}'

2,查找请求数请20个IP(常用于查找攻来源):

netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20
netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A[i],i}' |sort -rn|head -n20

3,用tcpdump嗅探80端口的访问看看谁最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

4,查找较多time_wait连接

netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

5,找查较多的SYN连接

netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

6,根据端口列进程

netstat -ntlp | grep 80 | awk '{print $7}' | cut -d/ -f1

第二部分,网站日志分析(Apache):
1,获得访问前10位的ip地址

cat access.log|awk '{print $1}'|sort|uniq -c|sort -nr|head -10
cat access.log|awk '{counts[$(11)]+=1}; END {for(url in counts) print counts[url], url}'

2,访问次数最多的文件或页面,取前20及统计所有访问IP

cat access.log|awk '{print $11}'|sort|uniq -c|sort -nr|head -20
awk '{ print $1}' access.log |sort -n -r |uniq -c|wc -l

3,列出传输最大的几个exe文件(分析下载站的时候常用)

cat access.log |awk '($7~/\.exe/){print $10 " " $1 " " $4 " " $7}'|sort -nr|head -20

4,列出输出大于200000byte(约200kb)的exe文件以及对应文件发生次数

cat access.log |awk '($10 > 200000 && $7~/\.exe/){print $7}'|sort -n|uniq -c|sort -nr|head -100

5,如果日志最后一列记录的是页面文件传输时间,则有列出到客户端最耗时的页面

cat access.log |awk '($7~/\.php/){print $NF " " $1 " " $4 " " $7}'|sort -nr|head -100

6,列出最最耗时的页面(超过60秒的)的以及对应页面发生次数

cat access.log |awk '($NF > 60 && $7~/\.php/){print $7}'|sort -n|uniq -c|sort -nr|head -100

7,列出传输时间超过 30 秒的文件

cat access.log |awk '($NF > 30){print $7}'|sort -n|uniq -c|sort -nr|head -20

8,统计网站流量(G)

cat access.log |awk '{sum+=$10} END {print sum/1024/1024/1024}'

9,统计404的连接

awk '($9 ~/404/)' access.log | awk '{print $9,$7}' | sort

10,统计http status.

cat access.log |awk '{counts[$(9)]+=1}; END {for(code in counts) print code, counts[code]}'
cat access.log |awk '{print $9}'|sort|uniq -c|sort -rn

11,每秒并发:

awk '{if($9~/200|30|404/)COUNT[$4]++}END{for( a in COUNT) print a,COUNT[a]}'|sort -k 2 -nr|head -n10

最新文章

  1. ASP.NET Core的配置(4):多样性的配置来源[上篇]
  2. 在IIS下部署Thinkphp项目,验证码不能显示的解决办法
  3. BIEE 10g 二次开发整理
  4. java基于socket公共聊天室的实现
  5. [LeetCode] Add Two Numbers
  6. 锋利的jQuery-4--给事件添加命名空间
  7. Erlang generic standard behaviours -- gen
  8. 我的一点关于把WndProc指向类的成员函数的看法
  9. Shell脚本文件操作
  10. 企业生产环境中linux系统分区的几种方案
  11. datatable 多字段 排序;
  12. vs2017无法安装
  13. 如何通过setTimeout理解JS运行机制详解
  14. 洛谷P2375 动物园
  15. BZOJ 2759 一个动态树好题(动态树)
  16. Hexo的next主题安装
  17. LVOOP设计模式在路上(二)-- 策略模式
  18. VS2015 无法启动 IIS Express Web 服务器 解决方案
  19. 大量界面刷新时手动Dispose也是有必要的
  20. Centos7源代码安装freeswitch和启动freeswitch

热门文章

  1. Maven settings配置阿里镜像
  2. sqlalchemy 执行sql
  3. Django笔记&教程 4-2 模型(models)中的Field(字段)
  4. go微服务框架Kratos笔记(七)使用jwt认证中间件
  5. Python 数据类型常用的内置方法(三)
  6. python实现图片色素的数值运算(加减乘除)和逻辑运算(与或非异或)
  7. [luogu5666]树的重心
  8. 大厂技术实现 | 腾讯信息流推荐排序中的并联双塔CTR结构 @推荐与计算广告系列
  9. 待办事项-redis
  10. P1759 通天之潜水(双写法+解析)