首页 > 学院 > 开发设计 > 正文

rule_add.py

2019-11-08 01:48:26
字体:
来源:转载
供稿:网友

#!/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()


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表