コード例 #1
0
    def get_as_name(self, asn: int):
        """Gets the name of the given ASN.

        Args:
            asn (int): The ASN to lookup.
        """
        if not bogons.valid_public_asn(asn):
            raise ValueError(f"{asn} is not a valid ASN")

        # Check local all_asnames first
        if self._all_as_names:
            self._status_code = 200
            if asn in self._all_as_names:
                self._as_name = self._all_as_names[asn]
                self._exists = True
                return
            self._exists = False
            return

        endpoint = "asname"
        resp = self._bgpstuff_request(f"{endpoint}/{asn}")

        if self.exists:
            self.as_name = resp["Response"]["ASName"]
            return

        self._as_name = None
コード例 #2
0
    def get_vrps(self, asn: int):
        """Gets all the Validated Roa Payloads (VRPs) for a given ASN.

        Args:
        asn (int): The ASN to check.
        """
        if not bogons.valid_public_asn(asn):
            raise ValueError(f"{asn} is not a valid ASN")

        endpoint = "vrps"
        resp = self._bgpstuff_request(f"{endpoint}/{asn}")

        self.vrps = resp["Response"]["VRPs"]
コード例 #3
0
    def get_sourced_prefixes(self, asn: int):
        """Gets a list of prefixes sourced by the given ASN.

        Args:
            asn (int): The ASN to lookup.
        """
        if not bogons.valid_public_asn(asn):
            raise ValueError(f"{asn} is not a valid ASN")

        endpoint = "sourced"
        resp = self._bgpstuff_request(f"{endpoint}/{asn}")

        self.sourced = resp["Response"]["Sourced"]["Prefixes"]
コード例 #4
0
    def get_invalids(self, asn: int = 0):
        """Gets a list of all invalid prefixes observed by the BGPStuff
        route collector.

        Args:
            asn (int): The ASN to lookup. Using 0 means ALL ASNs.
        """
        if asn != 0:
            if not bogons.valid_public_asn(asn):
                raise ValueError(f"{asn} is not a valid ASN")

        endpoint = "invalids"
        if asn == 0:
            resp = self._bgpstuff_request(f"{endpoint}/")
            self.all_invalids = resp["Response"]["Invalids"]
            return
コード例 #5
0
    def get_as_name(self, asn: int):
        """Gets the name of the given ASN.

        Args:
            asn (int): The ASN to lookup.

        Returns:
            as_name (str): The name of the given ASN.
        """
        if not bogons.valid_public_asn(asn):
            raise ValueError(f"{asn} is not a valid ASN")

        endpoint = "asname"
        resp = self._bgpstuff_request(f"{endpoint}/{asn}")

        self.as_name = resp["Response"]["ASName"]
コード例 #6
0
    def get_invalids(self, asn: int):
        """Gets a list of all invalid prefixes observed by the BGPStuff
        route collector.

        Args:
            asn (str): The ASN to lookup. Using 0 means ALL ASNs.

        Returns:
            resp (json): The JSON returned from the REST endpoint.
        """
        if not bogons.valid_public_asn(asn):
            raise ValueError(f"{asn} is not a valid ASN")

        endpoint = "invalids"
        resp = self._bgpstuff_request(f"{endpoint}/")

        invalid_list = resp["Response"]["Invalids"]

        invalids = {}
        for invalid in invalid_list:
            invalids[invalid["ASN"]] = invalid["Prefixes"]

        return invalids