快速过滤出IP添加到IPtables中

1、第一版:

# awk '{IP[$1]++}END{for( i in IP ) print IP[i],i}'  \

  logs/localhost_access_log.2016-12-10.txt |sort -nr | \

  head -n 130|awk '{print $2}' >111.txt

# awk '$1>=100{print $0}' 111.txt

# for i in `cat 111`;do iptables -I INPUT -s $i -j REJECT ;done


2、第二版

#!/bin/bash

File=$1

ExcludeIp="2.2.2.2|1.1.1.1"

awk '{IP[$1]++}END{for( i in IP ) print IP[i],i}' $File  | sort -nr |egrep -v "$ExcludeIp" > temp.ip

awk '$1>=10{print $0}' temp.ip > temp.ip.1


for i in `awk '{print $2}' temp.ip.1`

        do iptables -I INPUT -s $i -j REJECT

done