<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to View ACCESS LIST in ASA with counter 0 via CLI &amp;amp; disable in Network Security</title>
    <link>https://community.cisco.com/t5/network-security/how-to-view-access-list-in-asa-with-counter-0-via-cli-amp/m-p/4950942#M1105441</link>
    <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;I currently have a farm of ASA Firewalls (20 Device), and I need to perform the following tasks via CLI:&lt;/P&gt;&lt;P&gt;1st Be able to list all access lists with a counter of 0 that are not being used.&lt;/P&gt;&lt;P&gt;2nd From that filtered list with all those access lists created with that COUNTER 0 argument and via CLI through a Script or command routine, disable them mainly to eliminate them after a while.&lt;/P&gt;&lt;P&gt;It is possible that someone knows a routine that could make this job easier for me.&lt;/P&gt;&lt;P&gt;NOTE: Use the command show access-list | I access.*hitcnt=0 but this command does not generalize the access lists and in exchange it gives me a granular list for each hit 0 it finds.&lt;/P&gt;&lt;P&gt;I thank you through your experience for any recommendations to be able to do this task.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;&lt;P&gt;Harwin M Valero&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2023 15:11:57 GMT</pubDate>
    <dc:creator>Harwin M Valero L</dc:creator>
    <dc:date>2023-10-30T15:11:57Z</dc:date>
    <item>
      <title>How to View ACCESS LIST in ASA with counter 0 via CLI &amp; disable</title>
      <link>https://community.cisco.com/t5/network-security/how-to-view-access-list-in-asa-with-counter-0-via-cli-amp/m-p/4950942#M1105441</link>
      <description>&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;I currently have a farm of ASA Firewalls (20 Device), and I need to perform the following tasks via CLI:&lt;/P&gt;&lt;P&gt;1st Be able to list all access lists with a counter of 0 that are not being used.&lt;/P&gt;&lt;P&gt;2nd From that filtered list with all those access lists created with that COUNTER 0 argument and via CLI through a Script or command routine, disable them mainly to eliminate them after a while.&lt;/P&gt;&lt;P&gt;It is possible that someone knows a routine that could make this job easier for me.&lt;/P&gt;&lt;P&gt;NOTE: Use the command show access-list | I access.*hitcnt=0 but this command does not generalize the access lists and in exchange it gives me a granular list for each hit 0 it finds.&lt;/P&gt;&lt;P&gt;I thank you through your experience for any recommendations to be able to do this task.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you.&lt;/P&gt;&lt;P&gt;Harwin M Valero&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 15:11:57 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-security/how-to-view-access-list-in-asa-with-counter-0-via-cli-amp/m-p/4950942#M1105441</guid>
      <dc:creator>Harwin M Valero L</dc:creator>
      <dc:date>2023-10-30T15:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to View ACCESS LIST in ASA with counter 0 via CLI &amp; disabl</title>
      <link>https://community.cisco.com/t5/network-security/how-to-view-access-list-in-asa-with-counter-0-via-cli-amp/m-p/5201013#M1116191</link>
      <description>&lt;P&gt;To achieve your objectives, I recommend the following approach based on your requirements:&lt;/P&gt;&lt;P&gt;1. **List all access lists with a hit counter of 0**:&lt;BR /&gt;While the command `show access-list | include access.*hitcnt=0` gives you a granular output, it's not ideal for your use case because it doesn't group or generalize access lists efficiently. Instead, you can create a script to parse the output and extract only the ACL names with hit counts of 0, filtering out the individual hits.&lt;/P&gt;&lt;P&gt;2. **Disable access lists with hit count 0**:&lt;BR /&gt;After listing the ACLs with hitcnt=0, you want to disable them. This can be done by removing the relevant ACL entries or rules. I'll provide a basic workflow that you can adapt into a script.&lt;/P&gt;&lt;P&gt;### Step-by-Step Solution:&lt;/P&gt;&lt;P&gt;#### 1. **Generate the list of ACLs with hit count 0**:&lt;BR /&gt;Use a slightly modified command to capture all access lists that have a hit count of 0, and then parse the output to group them together by ACL name.&lt;/P&gt;&lt;P&gt;Command:&lt;BR /&gt;```bash&lt;BR /&gt;show access-list | include ^access-list|hitcnt=0&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;This command will show all ACL entries and their hit counts, but you'll need a script to filter and group them by ACL name.&lt;/P&gt;&lt;P&gt;#### 2. **Parse the output and filter ACLs**:&lt;BR /&gt;You can write a script in Python (or Bash, if preferred) that reads the output, identifies all access lists where every rule has a hitcnt=0, and then stores those ACL names.&lt;/P&gt;&lt;P&gt;Here’s an example in Python:&lt;BR /&gt;```python&lt;BR /&gt;import re&lt;/P&gt;&lt;P&gt;# Sample output from "show access-list"&lt;BR /&gt;output = """&lt;BR /&gt;access-list OUTSIDE_ACL; 1 elements; name hash: 0x123456&lt;BR /&gt;access-list OUTSIDE_ACL line 1 extended permit ip any any (hitcnt=0)&lt;BR /&gt;access-list INSIDE_ACL; 1 elements; name hash: 0xabcdef&lt;BR /&gt;access-list INSIDE_ACL line 1 extended deny tcp any any (hitcnt=5)&lt;BR /&gt;"""&lt;/P&gt;&lt;P&gt;acl_hitcnt_zero = set()&lt;BR /&gt;current_acl = None&lt;/P&gt;&lt;P&gt;for line in output.splitlines():&lt;BR /&gt;acl_match = re.match(r"access-list (\S+);", line)&lt;BR /&gt;hitcnt_match = re.search(r"hitcnt=(\d+)", line)&lt;/P&gt;&lt;P&gt;if acl_match:&lt;BR /&gt;current_acl = acl_match.group(1)&lt;BR /&gt;acl_hitcnt_zero.add(current_acl)&lt;/P&gt;&lt;P&gt;if hitcnt_match and current_acl:&lt;BR /&gt;if int(hitcnt_match.group(1)) != 0:&lt;BR /&gt;acl_hitcnt_zero.discard(current_acl)&lt;/P&gt;&lt;P&gt;print("ACLs with all hitcnt=0:", acl_hitcnt_zero)&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;The result will be a list of ACLs that have no traffic matched (hit count = 0).&lt;/P&gt;&lt;P&gt;#### 3. **Disable access lists with hitcnt=0**:&lt;BR /&gt;Once you've identified the access lists to be disabled, you can use the `no access-list` command to disable or remove them from the configuration.&lt;/P&gt;&lt;P&gt;Example command to disable an ACL:&lt;BR /&gt;```bash&lt;BR /&gt;no access-list ACL_NAME&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;You can either manually run this command for each ACL in your filtered list or include it in a script to automate the process.&lt;/P&gt;&lt;P&gt;Example in Python (using a list of ACLs to disable):&lt;BR /&gt;```python&lt;BR /&gt;acls_to_disable = ['OUTSIDE_ACL', 'ANOTHER_ACL']&lt;/P&gt;&lt;P&gt;for acl in acls_to_disable:&lt;BR /&gt;print(f"no access-list {acl}")&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;#### 4. **Automating the script execution**:&lt;BR /&gt;If you’re using a management platform (e.g., Ansible, Python with paramiko, or similar), you can automate the entire process of connecting to each ASA device, running the script to filter ACLs with hitcnt=0, and disabling them.&lt;/P&gt;&lt;P&gt;Here’s an example using Python and `paramiko` for SSH automation:&lt;BR /&gt;```python&lt;BR /&gt;import paramiko&lt;/P&gt;&lt;P&gt;def execute_asa_command(host, username, password, command):&lt;BR /&gt;ssh = paramiko.SSHClient()&lt;BR /&gt;ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())&lt;BR /&gt;ssh.connect(host, username=username, password=password)&lt;BR /&gt;stdin, stdout, stderr = ssh.exec_command(command)&lt;BR /&gt;return stdout.read().decode()&lt;/P&gt;&lt;P&gt;devices = ['ASA1_IP', 'ASA2_IP', 'ASA3_IP'] # List of ASA devices&lt;BR /&gt;for device in devices:&lt;BR /&gt;print(f"Connecting to {device}")&lt;BR /&gt;result = execute_asa_command(device, 'username', 'password', 'show access-list | include ^access-list|hitcnt=0')&lt;BR /&gt;print(result)&lt;BR /&gt;```&lt;/P&gt;&lt;P&gt;### Final Thoughts:&lt;BR /&gt;- **First step**: Run the `show access-list | include ^access-list|hitcnt=0` command to gather the data you need.&lt;BR /&gt;- **Second step**: Use a script to filter ACLs with hitcnt=0.&lt;BR /&gt;- **Third step**: Automate the removal or disabling of those ACLs.&lt;/P&gt;&lt;P&gt;This method gives you a definitive, automated approach to achieve the task you outlined, minimizing manual intervention and ensuring consistency across all devices.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 16:16:19 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-security/how-to-view-access-list-in-asa-with-counter-0-via-cli-amp/m-p/5201013#M1116191</guid>
      <dc:creator>Harwin M Valero L</dc:creator>
      <dc:date>2024-09-30T16:16:19Z</dc:date>
    </item>
  </channel>
</rss>

