1,查看apache进程:
ps aux | grep httpd | grep -v grep | wc
-l
2,查看80端口的tcp连接:
netstat -tan | grep "ESTABLISHED" | grep ":80" | wc
-l
3,通过日志查看当天ip连接数,过滤重复:
cat access_log | grep
"20/Oct/2008" | awk '{print $2}' | sort | uniq -c | sort
-nr
4,当天ip连接数最高的ip都在干些什么(原来是蜘蛛):
cat access_log | grep
"20/Oct/2008:00" | grep "122.102.7.212" | awk '{print $8}' | sort | uniq -c |
sort -nr | head -n 10
5,当天访问页面排前10的url:
cat access_log | grep "20/Oct/2010:00" | awk '{print $8}'
| sort | uniq -c | sort -nr | head -n 10
6,用tcpdump嗅探80端口的访问看看谁最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print
$1"."$2"."$3"."$4}' | sort | uniq -c | sort
-nr
<pre>
接着从日志里查看该ip在干嘛:
<pre lang="php">
cat access_log | grep 121.201.255.161|
awk '{print $1"\t"$8}' | sort | uniq -c | sort -nr |
less
7,查看某一时间段的ip连接数:
grep "2006:0[7-8]" www20060723.log |
awk '{print $2}' | sort | uniq -c| sort -nr | wc -l
几个应付DOS攻击的管理脚本
关键字: dos
$ cat dos_ip.sh
#!/bin/bash
netstat -an|grep SYN_RECV|awk -F' ' '{print $5;}'|awk
-F':' '{print $1;}'|sort| uniq -c | sort -nr | head -n $1
$ cat dos_attack.sh
#!/bin/bash
netstat -an|grep SYN_RECV|awk -F' ' '{print $5;}'|awk -F':' '{print
$1;}'|sort| uniq -c | sort -nr | head -n $1|awk -F' ' '{print $2}'|xargs
--replace=TTT /sbin/iptables -t filter -I INPUT 1 -m state --state NEW -m tcp -p
tcp -s TTT --dport 80 -j REJECT --reject-with
icmp-host-prohibited
$ cat nst.sh
#!/bin/bash
if [[ "1" != "1$1" ]]; then
netstat -an|grep $1|awk -F' '
'{print $5;}'|awk -F':' '{print $1;}'|sort| uniq -c | sort -nr | head -n
10
else
netstat -an|awk -F' ' '{print $5;}'|awk -F':' '{print
$1;}'|sort| uniq -c | sort -nr | head -n 10
fi