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.1

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.1
File Size Uploaded Provenance Actions
bogons-1.4.1.tar.gz 9.8 kB Without provenance Details for bogons-1.4.1.tar.gz

Built distribution (wheel)

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

Total release size: 19.7 kB

Release files / bogons-1.4.1.tar.gz

Download URL bogons-1.4.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0c006a2f5c1e0eed90ae07d13f5d5b6706b8febe47b84c8d07bc8d3eea0bc50c
BLAKE2b-256 checksum
How to use checksums
87f3be2c5515cb26901835bee829ddda2d4b8aeebaa93ae0bc81b84c9b941fb2
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.1-py3-none-any.whl

Download URL bogons-1.4.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbe54653342cd5fb735fc647680364b94fb1733ac88bea52998703c9394dc946
BLAKE2b-256 checksum
How to use checksums
d3b6eab1956eb8164975a149825206381dd7ffdb91abe8b88e7ef2340df633ea
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.1

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