博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
写程序find特定生效的iptables
阅读量:4229 次
发布时间:2019-05-26

本文共 1443 字,大约阅读时间需要 4 分钟。

#!/usr/local/bin/env python# -*- coding: utf-8 -*-from itertools import combinationsimport subprocessimport osimport paramikofile = 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_listfor 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  cdef 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()

转载地址:http://nznqi.baihongyu.com/

你可能感兴趣的文章
Visual C# 2005 Demystified
查看>>
Unlocking Microsoft C# V 2.0 Programming Secrets
查看>>
Programming Excel with VBA and .NET
查看>>
SQL Server 2005 T-SQL Recipes: A Problem-Solution Approach
查看>>
Core Python Programming
查看>>
Creating Database Web Applications with PHP and ASP
查看>>
ASP.NET 2.0 Demystified
查看>>
Pattern-Oriented Software Architecture, Volume 2, Patterns for Concurrent and Networked Objects
查看>>
Pattern-Oriented Software Architecture, Volume 1: A System of Patterns
查看>>
Database Programming with Visual Basic® .NET and ADO.NET: Tips, Tutorials, and Code
查看>>
Penetration Testing and Network Defense
查看>>
Object-Oriented Programming: From Problem Solving to Java
查看>>
Linux Network Security
查看>>
Essential SourceSafe
查看>>
Office 2003 Application Development All-in-One Desk Reference For Dummies
查看>>
Access Database Design and Programming
查看>>
Knowledge-Based Clustering : From Data to Information Granules
查看>>
The Hands-On Project Office: Guaranteeing ROI and On-Time Delivery
查看>>
Expert Oracle9i Database Administration
查看>>
.NET Framework Solutions: In Search of the Lost Win32 API
查看>>