Created
January 16, 2018 08:06
-
-
Save spdkils/316289ee34880982b927785cda1a1d53 to your computer and use it in GitHub Desktop.
Ugly Function to flip ACE statements. (Usable to see if outbound has properly inverted statements.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def flipACE(ace: str) -> list: | |
search = r'(?:host \d+\.\d+\.\d+\.\d+|\d+\.\d+\.\d+\.\d+ \d+\.\d+\.\d+\.\d+|any)' | |
endofline = r'(?:established|log-input|log|$)' | |
remark = r'^ ?remark' | |
if re.search(remark, ace): | |
return ace.split() | |
if re.search(' reflect ', ace): | |
return '! should not be flipped reflexive'.split() | |
end = re.search(endofline, ace) | |
srcthendest = re.finditer(search, ace) | |
source = srcthendest.__next__() | |
destination = srcthendest.__next__() | |
aceAction = slice(0, source.start()) | |
sourceAndPorts = slice(source.start(), destination.start()) | |
destinationAndPorts = slice(destination.start(), end.start()) | |
# sourceports = slice(source.end(), destination.start()) | |
# destinationports = slice(destination.end(), end.end()) | |
return [ace[aceAction].strip(), | |
ace[destinationAndPorts].strip(), | |
ace[sourceAndPorts].strip() | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment