写程序find特定生效的iptables

#!/usr/local/bin/env python

# -*- coding: utf-8 -*-

from itertools import combinations
import subprocess
import os
import paramiko

file = open('/home/jxie/drop_all.sh','r')
iptables_list = []
#while 1:
#    lines = file.readlines(1000)
#    if not lines:
#       break
#    for line in lines:
#		iptables_list.append(line)
#print iptables_list
for line in file:
    iptables_list.append(line.rstrip())

def find_all_sublist(mylist):
     #for len in range(1,len(mylist)):
    for len in range(1,6):
	for c in combinations(iptables_list,len):
	   yield  c

def vyos_ping_check():
	hostname=raw_input('10.61.34.102')
	username='jxie'
	password='!'
	ssh=paramiko.SSHClient()
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	ssh.connect(hostname,22,username,password)
	stdin,stdout,stderr=ssh.exec_command('ping -c 5 10.141.177.14')
	print stdout.readlines()
	ssh.close
	if 'ttl=64' in stdout.readline:
		return True
	else:
		return False
	
def main():
    print 'hhhhh'
    with open('/tmp/result.txt','w') as f:
        for sub in find_all_sublist(iptables_list):
	    for s in sub:
                print s
                print type(s)
	        subprocess.call(s.split())

		if vyos_ping_check == True:
		    f.write(sub + os.linesep)
		    for rule in sub:
	                subprocess.call(('echo iptables -A ' + rule[15:]).split())
	        else:
		    for l in sub:
		        subprocess.call(('echo iptables -A ' + l[15:]).split())

if __name__ == '__main__':
    print 'hahah'
    main()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值