plutils.py
is a modular, extensible Python CLI tool for interacting with AWS Managed Prefix Lists (PLs). It provides three primary subcommands:
- search: Look up prefix list entries by IP or description.
- audit: Identify large CIDR blocks in customer-managed PLs.
- list: Retrieve a list of customer-managed PLs, with flexible filtering.
This tool uses boto3 and botocore under the hood and supports AWS CLI profiles for multi-account environments.
-
Modular Architecture
Code is organized into separate modules undermodules/
:aws_helpers.py
: AWS session helpers and prefix list retrieval/filtering.search_pl.py
: Functions for searching PL entries.audit_pl.py
: Functions to filter PL entries by CIDR size.list_pl.py
: Functions to list and filter prefix lists.utils.py
: Logging setup and CSV export utilities.
-
Customer-Managed PL Focus
Restricts operations to prefix lists owned by the AWS account (though you can tweak to include vendor or shared lists if needed). -
Filtering Options
--plfilter
to include only PLs whose names contain a specific substring.--plexclude
to exclude any PLs whose names contain a specified substring.
-
CSV Output
Most subcommands support--csv [filename]
to export results in a structured CSV format. -
Robust Logging
- Always writes logs to
logs/
(unique file per run). - Console logging can be toggled with
-v/--verbose
.
- Always writes logs to
-
PEP 8 Compliant
Code is kept tidy and consistent with Python best practices.
- Python 3.6+
- AWS CLI configured with valid credentials or environment variables.
- Install dependencies from
requirements.txt
:pip install -r requirements.txt
- (Optional) Virtual Environment:
If you prefer isolation, create a venv:python -m venv venv source venv/bin/activate pip install -r requirements.txt
Run the CLI entry point:
python plutils.py <subcommand> [options]
Search for entries by description or CIDR:
python plutils.py search --name "internal" --plfilter "Prod" --csv
Options:
--name
(searchesDescription
field)--ip
(searchesCidr
field)--plfilter
,--plexclude
--profile
,--region
(AWS settings)--csv [optional_filename]
Identify CIDR blocks larger than the specified prefix:
python plutils.py audit --maxcidr /28 --plfilter "Corp"
Options:
--maxcidr
: e.g.,/29
or29
- Common filters:
--plfilter
,--plexclude
- AWS config:
--profile
,--region
--csv [filename]
List customer-managed prefix lists, optionally filtered by name:
python plutils.py list --plexclude "Old"
Options:
--plfilter
,--plexclude
- AWS config:
--profile
,--region
--csv [filename]
- File Logging: Always logs to
logs/plutils_<subcommand>-<timestamp>.log
. - Console Logging: Set
-v/--verbose
to see INFO messages; otherwise only CRITICAL logs appear.
We use the standard unittest
framework. All test files are located under tests/
. Run them with:
python -m unittest discover -s tests
Tests cover:
- AWS Helpers (
test_aws_helpers.py
) - Search Logic (
test_search_pl.py
) - Audit Logic (
test_audit_pl.py
) - List Logic (
test_list_pl.py
) - Utilities & Logging (
test_utils.py
,test_logging.py
)
Before committing, verify tests pass and lint with pylint
or similar to maintain code quality.
- Fork or clone this repository.
- Create a feature branch.
- Update and add tests where appropriate.
- Submit a pull request with a clear description of changes.
This project is licensed under the MIT License — see the LICENSE
file for details.