Skip to main content

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)"

# Accepts string with optional "AS" prefix or asdot notation:
valid, reason = bogons.check_asn("AS64512")
# Output: False "RFC 1930 / RFC 6996 (Private-Use 16-bit)"

valid, reason = bogons.check_asn("1.0")
# Output: False "RFC 5398 (Documentation 32-bit)"

bogons.valid_public_asn("AS15169")  # True
bogons.valid_public_asn("AS64512")  # False

License

Apache-2.0

Metadata

Release files for bogons 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bogons 1.4.0
File Size Uploaded Provenance Actions
bogons-1.4.0.tar.gz 9.8 kB Without provenance Details for bogons-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bogons 1.4.0
File Interpreter ABI Platform Actions
bogons-1.4.0-py3-none-any.whl Python 3 none any Details for bogons-1.4.0-py3-none-any.whl

Total release size: 19.7 kB

Release files / bogons-1.4.0.tar.gz

Download URL bogons-1.4.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
55c85a17400f7a6903f32e2298698919a16c4a568cedc24f0e4a927f9751b674
BLAKE2b-256 checksum
How to use checksums
35f06c9b62cbda7de7aa529225d5f420e490b62e47fcb54c0b89080c04bc1d86
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.4.0-py3-none-any.whl

Download URL bogons-1.4.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0638783de1c216e2598f7144e28facc718925f6f641bda49ae08cfabce4a8108
BLAKE2b-256 checksum
How to use checksums
5625aacf252a298f3f82cc0365eb70d840f08f28fb6deb6ec4745d7004631ef6
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.4.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page