API

Entry point of the API

bgpranking.api.cache_get_daily_rank(asn, source='global', date=None)[source]

From the temporary database

Get a single rank.

Parameters:
  • asn – Autonomous System Number
  • source – Source to use. global is the aggregated view for all the sources
  • date – Date of the information (default: last ranked day)
Return type:

List

Note

Format of the list

[asn, date, source, rank]

bgpranking.api.cache_get_top_asns(source='global', date=None, limit=50, with_sources=True)[source]

From the temporary database

Get worse ASNs.

Parameters:
  • source – Source used to rank the ASNs. global is the aggregated view for all the sources
  • date – Date of the information (default: last ranked day)
  • limit – Number of ASNs to get
  • with_sources – Get the list of sources where each ASN has been found.
Return type:

Dictionary

Note

Format of the Dictionary

{
    'source': source,
    'date': date,
    'top_list':
        [
            ((asn, rank), set([source1, source2, ...])),
            ...
        ]
}

The set of sources is only presetn if with_sources is True

bgpranking.api.get_all_ranks_all_asns(dates_sources, with_details_sources=False)[source]

Get all ranks for all the ASNs on a timeframe.

Parameters:
  • dates_sources

    Dictionaries of the dates and sources

    Note

    Format of the dictionary:

    {
        YYYY-MM-DD: [source1, source2, ...],
        YYYY-MM-DD: [source1, source2, ...],
        ...
    }
    
  • with_details_sources – Also returns the ranks by sources
Rype :

Dictionary

Note

Format of the dictionary:

{
    YYYY-MM-DD:
        {
            asn1 :
                {
                    'details':
                        [
                            (source1, rank),
                            (source2, rank),
                            ...
                        ],
                    'total': sum_of_ranks
                }
            ...
        }
    ...
}

The details key is only present if with_details_sources is True.

bgpranking.api.get_all_ranks_single_asn(asn, dates_sources, with_details_sources=False)[source]

Get all the ranks on a timeframe for a single ASN.

Parameters:
  • asn – Autonomous System Number
  • dates_sources

    Dictionaries of the dates and sources

    Note

    Format of the dictionary:

    {
        YYYY-MM-DD: [source1, source2, ...],
        YYYY-MM-DD: [source1, source2, ...],
        ...
    }
    
  • with_details_sources – Returns the details by sources if True
Rype :

Dictionary

Note

Format of the output:

{
    date1:
        {
            'details':
                [
                    (source1, rank),
                    (source2, rank),
                    ...
                ],
            'total': sum_of_ranks
        }
    ...
}

The details key is only present if with_details_sources is True.

bgpranking.api.get_asn_descs(asn, date=None, sources=None)[source]

Get all what is available in the database about an ASN for one day

Parameters:
  • asn – Autonomous System Number
  • date – Date of the information (default: last ranked day)
  • sources – List of sources (default: the available sources at date)
Return type:

Dictionary

Note

Format of the dictionary:

{
    'date': date,
    'sources': [source1, source2, ...],
    'asn': asn,
    asn:
        {
            'clean_blocks':
                [
                    (timestamp, block, descr),
                    ...
                ],
            'old_blocks':
                [
                    (timestamp, block, descr),
                    ...
                ],
            asn_timestamp:
                {
                    'owner': owner_description,
                    'ip_block': block,
                    'nb_of_ips': nb,
                    'sources': [source1, source2, ...]
                    'rank': subnet_rank
                },
            ...
        }
}

bgpranking.api.get_daily_rank_multiple_asns(asns, date, source)[source]

Get the ranks of a list of ASNs for one day and one source.

Parameters:
  • asns – list of ASNs
  • date – date of the rank (format: YYYY-MM-DD)
  • source – name of the source for the rank
Return type:

list of rank by ASN

Note

Format of the output:

[
    (asn1, rank),
    (asn2, rank),
    ...
]

bgpranking.api.get_ips_descs(asn, asn_timestamp, date=None, sources=None)[source]

Get all what is available in the database about an subnet for one day

Parameters:
  • asn – Autonomous System Number
  • asn_timestamp – First the subnet has been seen in the db (for this ASN)
  • date – Date of the information (default: last ranked day)
  • sources – List of sources (default: the available sources at date)
Return type:

Dictionary

Note

Format of the dictionary:

{
    'date': date,
    'sources': [source1, source2, ...],
    'asn': asn,
    'timestamp': asn_timestamp
    asn_timestamp:
        {
            ip: [source1, source2, ...],
            ...
        }
}

bgpranking.api.get_owner(asn, block)[source]

Get the description of the ASN (usually the owner name).

Parameters:
  • asn – Autonomous System Number
  • block – IP Block you are looking for
Return type:

List

Note

Format of the list:

[asn, block, owner]

bgpranking.api.get_stats()[source]

Return amount of asn and subnets found by source, for all the cached days.

Return type:Dictionary

Note

Format of the Dictionary

{
    date:
        {
            'sources':
                {
                    source : [nb_asns, nb_subnets],
                    ...
                },
            'total_asn': total_asn
            'total_subnets': total_subnets
        }
    ...
}
bgpranking.helper_global.asn_exists(asn)[source]

Check if the ASN exists in the database.

bgpranking.helper_global.daily_sources(dates)[source]

Get the sources parsed during a list of dates

Parameters:dates – List of dates
Return type:Set of sources for each date
bgpranking.helper_global.get_all_weights(date=None)[source]

Get the weights for all the sources.

Parameters:date – Date of the information (default: last ranked day)
Return type:Dictionary

Note

Format of the dictionary:

{
    source: date,
    ...
}
bgpranking.helper_global.get_default_date()[source]

Get the latest ranked day.

bgpranking.helper_global.get_sources_by_dates(sources, last_day=None, timeframe=None)[source]

Get a dictionary of sources by dates. Only with the sources passed in parameter IF they exist for the day. :param sources: List of sources :param last_day: Last day of the interval :param timeframe: size of the interval

Return type:Dictionary

Note

Format of the dictionary:

{
    date: [source1, source2, ...],
    ...
}
bgpranking.helper_global.last_seen_sources(date_sources)[source]

Get the last time a source has been seen. :param dates_sources: Dictionaries of the dates and sources

Note

Format of the dictionary:

{
    YYYY-MM-DD: [source1, source2, ...],
    YYYY-MM-DD: [source1, source2, ...],
    ...
}
Rype :

Dictionary

Note

Format of the dictionary:

{
    source: date,
    ...
}
bgpranking.helper_global.prepare_sources_by_dates(last_day=None, timeframe=None)[source]

Get a dictionary of sources by dates.

Parameters:
  • last_day – Last day of the interval
  • timeframe – size of the interval
Return type:

Dictionary

Note

Format of the dictionary:

{
    date: [source1, source2, ...],
    ...
}

Previous topic

Welcome to BGP Ranking Python API’s documentation!

This Page