linux查看外网访问IP

对连接的IP按连接数量进行排序  
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n  


查看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  


查看80端口连接数最多的20个IP    
netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20  
 
查找较多time_wait连接  
  
netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20  
查找较多的SYN连接  
netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more 


查看当前并发访问数:
netstat -an | grep ESTABLISHED | wc -l


查看所有连接请求
netstat -tn 2>/dev/null 
但是只要established的,则grep  "ESTABLISHED" 
netstat -tn | grep ESTABLISHED 2>/dev/null


查看访问某一ip的所有外部连接IP(数量从多到少)


netstat -nt | grep 121.41.30.149:80 | awk '{print $5}' | awk -F: '{print ($1>$4?$1:$4)}' | sort | uniq -c | sort -nr | head


根据端口查找进程


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


下面未验证


防范DDOS攻击脚本  


#防止SYN攻击 轻量级预防  
iptables -N syn-flood  
iptables -A INPUT -p tcp –syn -j syn-flood  
iptables -I syn-flood -p tcp -m limit –limit 3/s –limit-burst 6 -j RETURN  
iptables -A syn-flood -j REJECT  


#防止DOS太多连接进来,可以允许外网网卡每个IP最多15个初始连接,超过的丢弃  
iptables -A INPUT -i eth0 -p tcp –syn -m connlimit –connlimit-above 15 -j DROP  
iptables -A INPUT -p tcp -m state –state ESTABLISHED,RELATED -j ACCEPT  


#用Iptables抵御DDOS (参数与上相同)  
iptables -A INPUT  -p tcp --syn -m limit --limit 12/s --limit-burst 24 -j ACCEPT  
iptables -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT   






根据nginx的访问日志判断
查看访问记录
1.从1000行开始到3000
cat access.log |head -n 3000|tail -n 1000
2.从1000行开始,显示200行
cat access.log |tail -n +1000 |head -n 200
3.


通过查询日志记录进行分析(如果没有单独配置,access.log一般放在nginx/logs下)
awk '{print $1}' 日志地址 | sort | uniq -c | sort -n -k 1 -r | head -n 100


tail -n 1000:显示最后1000行
tail -n +1000:从1000行开始显示,显示1000行以后的
head -n 1000:显示前面1000行


1.根据访问IP统计UV


awk '{print $1}'  access.log|sort | uniq -c |wc -l


2.统计访问URL统计PV


awk '{print $7}' access.log|wc -l


3.查询访问最频繁的URL


awk '{print $7}' access.log|sort | uniq -c |sort -n -k 1 -r|more


4.查询访问最频繁的IP


awk '{print $1}' access.log|sort | uniq -c |sort -n -k 1 -r|more


5.根据时间段统计查看日志


 cat  access.log| sed -n '/14\/Mar\/2015:21/,/14\/Mar\/2015:22/p'|more


6.通过日志查看含有send的url,统计ip地址的总连接数
cat access.log | grep "send" | awk '{print $1}' | sort | uniq -c | sort -nr


7.通过日志查看当天访问次数最多的时间段
awk '{print $4}' access.log | grep "24/Mar/2011" |cut -c 14-18|sort|uniq -c|sort -nr|head


8.通过日志查看当天指定ip访问次数过的url和访问次数
cat access.log | grep "222.132.90.94" | awk '{print $7}' | sort | uniq -c | sort -nr
  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值