Quick ACL Entry Comparison Script

The ACL_compare function takes two lists of strings and compares the first to the second and returns a list comprising strings that are present in the first that are not in the second.

The listconvert function converts a file read into memory into a list of strings. Handy for when you use filenames as arguments when you run the script.

Essentially it’s all just string comparison really.


#Simple Python script to print absent ACL entries absent in a new rulebase when compared with an existing rulebase

import sys

def ACL_compare(fwsm_ACL,asa_ACL):
comparison=[]
for line in fwsm_ACL:
if line in asa_ACL:
pass
else:
comparison.append(line)
return comparison

def listconvert(file):
newlist=file.readlines()
return newlist

def listprint(somelist):
for line in somelist:
print line

def main():
print("usage: ACL_compare.py fwsm_rulebase_file asa_rulebase_file")
fwsm_rulebase=open(sys.argv[1],'r')
asa_rulebase=open(sys.argv[2],'r')
fwsm_rulebase_list=listconvert(fwsm_rulebase)
asa_rulebase_list=listconvert(asa_rulebase)
difference=ACL_compare(fwsm_rulebase_list,asa_rulebase_list)
print ("differing entries are")
listprint(difference)

if __name__=="__main__":
main()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s