python-bogons
Python version of github.com/mellowdrifter/bogons.
A lightweight Python library to validate IP address, subnet prefix, and ASN bogons with RFC explanations. Uses only Python's standard library (ipaddress).
Features
- IP Validation & Reasons: Test whether an IPv4 or IPv6 address is publicly routable, with exact RFC reason reporting (
check_ip). - Prefix & Subnet Validation: Check if an IP or subnet falls inside a bogon range (
check_prefix, ignores BGP announcement length filters) or enforce BGP routing limits (valid_public_prefix). - ASN Validation & Reasons: Verify if an Autonomous System Number is public or reserved/private (
check_asn). - RFC Compliant: Updated with RFC 1122, RFC 1918, RFC 6598, RFC 5737, RFC 7526, RFC 7535, RFC 7450, RFC 7534, RFC 9385, RFC 8880, RFC 7725, RFC 8155, RFC 6483, RFC 7300, etc.
- Zero Dependencies: Pure Python standard library (
ipaddress).
Installation
pip install bogons
Usage
IP Validation with RFC Reasons
import bogons
valid, reason = bogons.check_ip("1.1.1.1")
print(valid, reason)
# Output: True ""
valid, reason = bogons.check_ip("10.0.0.1")
print(valid, reason)
# Output: False "RFC 1918 (Private-Use)"
valid, reason = bogons.check_ip("2001:db8::1")
print(valid, reason)
# Output: False "RFC 3849 (Documentation)"
Boolean-only checks remain available:
bogons.is_public_ip("1.1.1.1") # True
bogons.is_public_ip("10.0.0.1") # False
bogons.is_public_ip("2600::") # True
Prefix & Subnet Validation
Use check_prefix to determine if a subnet sits within public space (ignoring BGP route boundary filters):
valid, reason = bogons.check_prefix("8.8.8.0/25")
print(valid, reason)
# Output: True ""
valid, reason = bogons.check_prefix("192.168.1.0/24")
print(valid, reason)
# Output: False "RFC 1918 (Private-Use)"
To enforce strict BGP announcement length limits (/8–/24 for IPv4, /16–/48 for IPv6) and reject host bits:
bogons.valid_public_prefix("8.8.8.0/24") # True
bogons.valid_public_prefix("8.8.8.0/25") # False (too specific for BGP)
bogons.valid_public_prefix("8.8.8.1/24") # False (host bits set)
ASN Validation with RFC Reasons
valid, reason = bogons.check_asn(15169)
print(valid, reason)
# Output: True ""
valid, reason = bogons.check_asn(64512)
print(valid, reason)
# Output: False "RFC 1930 / RFC 6996 (Private-Use 16-bit)"
bogons.valid_public_asn(15169) # True
bogons.valid_public_asn(64512) # False
License
Apache-2.0
Metadata
Release files for bogons 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bogons-1.3.0.tar.gz | 9.3 kB | Without provenance | Details for bogons-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bogons-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for bogons-1.3.0-py3-none-any.whl |
Total release size: 18.8 kB
Release files / bogons-1.3.0.tar.gz
| Download URL | bogons-1.3.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f7dd4bbb0c0516ce728689d8dd47f47637be2b27e9346da19aa0c5db594383e
|
|
BLAKE2b-256 checksum How to use checksums |
e1cf83d998b342730f2ab5319cd6bc292b877cffe1e659792867582ba67f75db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / bogons-1.3.0-py3-none-any.whl
| Download URL | bogons-1.3.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f57fdc476f574acb6919be63af9ec08421c6a2e363553c1e26fd27b5351867a3
|
|
BLAKE2b-256 checksum How to use checksums |
95dece1bdba1f3d84ccc0911ec6a6c251c1b48e0310f174a88263241bad8d352
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for bogons 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.