rule_add.py

#!/bin/env python

#-*- coding:UTF-8 -*-
import os
os.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:  
        break
f1.close()

f.close()



删除规则 rule_clear.py

#!/bin/env python
#-*- coding:UTF-8 -*-
import os
f = open("log.txt", "r")
while True:
        line=f.readline()
        if line:
                line=line.strip()
                print line
                os.system(line)
        else:
                break

f.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值