#!/bin/env python
#-*- coding:UTF-8 -*-import osos.system("netstat -tn 2>/dev/null | grep :1521 |grep 'ESTABLISHED'| awk '{PRint $5}' | cut -d: -f 1 | sort | uniq -c | sort -nr >/root/scripts/connect_Oracle.txt")f = open("/root/scripts/connect_oracle.txt", "r") f1= open("/root/scripts/log.txt","a") while True: line = f.readline() if line: pass # do something here line=line.strip() lnum=line.split(' ') if int(lnum[0])>30: #print lnum[1] ip=lnum[1].split('.') #print int(ip[2]) if int(ip[2]) <> 102: #print lnum[1] print "iptables -I INPUT -s "+lnum[1]+" -p tcp --dport 1521 -j DROP" os.system("/sbin/iptables -I INPUT -s "+lnum[1]+" -p tcp --dport 1521 -j DROP") f1.write("/sbin/iptables -D INPUT -s "+lnum[1]+" -p tcp --dport 1521 -j DROP/n") else: pass else: pass else: breakf1.close()f.close()
删除规则 rule_clear.py
#!/bin/env python#-*- coding:UTF-8 -*-import osf = open("log.txt", "r")while True: line=f.readline() if line: line=line.strip() print line os.system(line) else: breakf.close()
新闻热点
疑难解答