Sunday, June 4, 2017

Parsing firewall rules in Python

parts = rule.split(" ")
aclName, _, lineNumber, _, action, protocol = parts[:6]
endpoints = parts[6:]

def get_endpoint(eps):
    host, port = "*", "*"
    if eps[0] == "host":
        host = eps[1]
        eps = eps[2:]
    elif eps[0] == "any":
        eps = eps[1:]
    else:
        host = eps[0] + "/" + mask_to_bits(eps[1])
        eps = eps[2:]

    if eps and eps[0] == 'eq':
        port = eps[1]
        eps = eps[2:]
    return host, port, eps

sourceIP, sourcePort, endpoints = get_endpoint(endpoints)
destIP, destPort, endpoints = get_endpoint(endpoints)
https://stackoverflow.com/questions/10196998/parsing-firewall-rules-in-python

No comments:

China US AI URGENT meeting adversial attack ( Alibaba site commercial attack )

 https://www.abc.net.au/news/2026-05-12/trump-xi-beijing-summit-must-confront-ai-cold-war/106666482 https://www.thewirechina.com/2026/03/29/...