How dhakshi03/ip_access_manager works
Purpose and Entry Point
IP Access Manager is a local Python 3.8+ security-administration CLI that reconciles an IPv4 allowlist against a blocklist. Its executable entry point is ip_access_manager.py; operators supply the JSON state file as a positional argument, optionally with verbose or dry-run flags. The repository’s active policy data is ip_config.json.
CLI and Orchestration
ip_access_manager.py owns argument parsing, exception reporting, execution sequencing, and the final summary. It coordinates load → optional backup → validation/cleanup → persistence → audit reporting. Custom manager/config exceptions separate expected configuration and filesystem failures from generic failures.
• ip_access_manager.py
• Sample_Run_Windows_PowerShell.txt
Configuration Boundary
The JSON document is the system of record and contains two collections: allowed and blocked. Loading enforces readable, well-formed configuration; saving writes the reconciled lists back to that same source. This creates a clear mutable-state boundary: policy is file-backed rather than served by a database or remote API.
• ip_config.json
• ip_access_manager.py
Validation and Policy Reconciliation
The core processing stage validates each candidate as an IPv4 address using the Python standard library. Invalid entries from either list are excluded and audited. The resulting valid blocked set is then applied to the valid allowlist, ensuring a blocked address cannot remain permitted. The allowlist is rebuilt rather than modified during iteration.
• ip_access_manager.py
• ip_config.json
Mutation Safety: Backup and Dry Run
Before a real configuration update, the tool creates a timestamped copy under a runtime-generated backups/ directory. Dry-run preserves the full validation and decision flow but suppresses backup and configuration writes, allowing operators to inspect expected effects before committing policy changes.
• ip_access_manager.py
• ip_config.json
Audit and Operator Feedback
Each validation failure and blocked-allowlist removal is recorded with a timestamp in a runtime-generated log.txt. Verbose mode emits per-IP decisions; every execution produces aggregate counts and whether files changed. Logs and backups are operational artifacts, not versioned repository inputs.
• ip_access_manager.py
• Sample_Run_Windows_PowerShell.txt
Runtime and Dependencies
This is a single-process, local command-line program with no web service, database, cloud infrastructure, or third-party package dependency. Material integrations are the host filesystem and Python standard-library modules for CLI parsing, JSON, IPv4 parsing, timestamps, copying, and file operations.
• ip_access_manager.py
• README.md
Main entry points: ip_access_manager.py Config load and save · ip_config.json Policy JSON · Sample_Run_Windows_PowerShell.txt PowerShell example · README.md Runtime documentation
Components 13
Operator Interface
- IP Access Manager CLI · Parses arguments, sequences execution, handles errors, and prints the final summary.
ip_access_manager.py - Verbose and dry-run flags · Dry-run suppresses mutation; verbose exposes per-IP decisions.
ip_access_manager.py - PowerShell example
Sample_Run_Windows_PowerShell.txt - Execution summary · Reports aggregate counts and whether files changed.
ip_access_manager.py - Runtime documentation
README.md
Reconciliation Engine
- Config load and save · Reads validated JSON state and persists reconciled lists to the same file.
ip_access_manager.py - Manager/config errors · Separates expected configuration and filesystem failures from generic errors.
ip_access_manager.py - IPv4 validation · Excludes malformed addresses from both policy lists.
ip_access_manager.py - Allowlist reconciliation · Rebuilds the valid allowlist after removing addresses present in the valid blocklist.
ip_access_manager.py - Mutation decision · Determines whether reconciliation changed state and whether writes are permitted.
ip_access_manager.py
File-backed State
- Policy JSON · Contains mutable allowed and blocked IPv4 collections.
ip_config.json
Runtime Artifacts
- Timestamped backup · Created before a real configuration update.
- Audit log · Records invalid entries and blocked-allowlist removals with timestamps.
Connections 18
- PowerShell example → IP Access Manager CLI: shows invocation
- Runtime documentation → IP Access Manager CLI: documents
- Verbose and dry-run flags → IP Access Manager CLI: controls execution
- IP Access Manager CLI → Config load and save: loads state
- Policy JSON → Config load and save: JSON input
- Config load and save → Manager/config errors: configuration failures
- Config load and save → IPv4 validation: allowed and blocked lists
- IPv4 validation → Allowlist reconciliation: valid lists
- IPv4 validation → Audit log: invalid entries
- Allowlist reconciliation → Audit log: removed allowed addresses
- Allowlist reconciliation → Mutation decision: reconciled state
- Mutation decision → Timestamped backup: real update only
- Timestamped backup → Config load and save: then permit save
- Mutation decision → Config load and save: save unless dry-run
- Config load and save → Policy JSON: persist reconciled policy
- IP Access Manager CLI → Execution summary: reports results
- Mutation decision → Execution summary: change status
- Manager/config errors → Execution summary: reported failure