Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:40:27+00:00 2026-06-02T06:40:27+00:00

I am writing a script to parse firewall rules from the configuration of a

  • 0

I am writing a script to parse firewall rules from the configuration of a Cisco ASA.

Examples of my input include:

access-list myACL line 1 extended permit tcp host 10.8.13.200 host 10.32.53.22 eq 1122
access-list myACL line 2 extended permit tcp 10.8.13.0 255.255.255.0 host 10.1.206.17 eq 445 
access-list myACL line 3 extended permit udp host 10.8.13.200 eq 54345 host 10.1.206.17 eq 445
access-list myACL line 4 extended permit icmp any any

My desired output, in the form of a .csv, for the three lines above would be the following. However, these could just as well be tuples to be stored in a database.

#aclName,lineNumber,action,protocol,sourceIP,sourcePort,destIP,destPort
myACL,1,permit,tcp,10.8.13.200,*,10.32.53.22,1122
myACL,2,permit,tcp,10.8.13.0/24,*,10.1.206.17,445
myACL,3,permit,udp,10.8.13.200,54345,10.1.206.17,445
myACL,4,permit,icmp,*,*,*,*

I’m having trouble choosing an approach to this project. I’ve looked at many options including ats, shlex, or even just using a regex, but I’m having difficulty determining what the best option is. Would PLY help here?

What would be a suitable approach for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:40:29+00:00Added an answer on June 2, 2026 at 6:40 am

    The first 6 fields seem to be quite predictable, that leaves the endpoint which can have several representations. A possibility would be (untested code, but I hope you get the idea):

    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)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing following script to read list of servers from the text file
I'm writing a script to parse a KML file using JAXB and MOXy, but
I'm currently writing a simple .sh script to parse an Exim log file for
I'm writing a script that parses the pure-ftpwho -s command to get a list
im writing a script to get services from local and remote machines. I've had
I'm writing a script that should set filesystem access rights for a folder and
I'm writing a script to parse some text files, and insert the data that
I am writing a script that will transfer a file from one server to
I am writing a script for customising a configuration file. I want to replace
I'm writing a bash script that needs to parse html that includes special characters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.