osrg / gobgp

BGP implemented in the Go Programming Language
https://osrg.github.io/gobgp/
Apache License 2.0
3.66k stars 699 forks source link

Verify RPKI with only AS Number? #2269

Open hazcod opened 4 years ago

hazcod commented 4 years ago

Hi, is it possible to verify whether an AS Number is being protected by RPKI using this library, but without supplying route servers or RPKI servers? Just wondering. Thanks.

ljluestc commented 3 months ago
import rpki_client

def verify_asn_protected_by_rpki(asn):
    try:
        # Initialize the RPKI client
        client = rpki_client.Client()

        # Fetch the validated ROAs (Route Origin Authorizations)
        roas = client.fetch_roas()

        # Check if the given ASN is in any of the ROAs
        for roa in roas:
            if roa.asn == asn:
                print(f"AS Number {asn} is protected by RPKI.")
                return True

        print(f"AS Number {asn} is NOT protected by RPKI.")
        return False
    except Exception as e:
        print(f"An error occurred: {e}")
        return False

# Example usage
asn_to_check = 12345
verify_asn_protected_by_rpki(asn_to_check)