Initial commit
This commit is contained in:
commit
d168eeaa64
15
LICENSE
Normal file
15
LICENSE
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
ISC License
|
||||||
|
|
||||||
|
Copyright (c) 2023, acidvegas <acid.vegas@acid.vegas>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
37
README.md
Normal file
37
README.md
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# MANRS API
|
||||||
|
![](logo.png)
|
||||||
|
|
||||||
|
This is a Python wrapper for the [MANRS](https://www.manrs.org/) API, designed to simplify the process of making requests to the MANRS Public API. This class assists in querying data related to routing security, such as ROAs by ASN or country, ASN info, IXP info, and conformance details for CDNs, IXPs, network operators, and equipment vendors.
|
||||||
|
|
||||||
|
The official documentation for the MANRS API can be found [here](https://manrs.stoplight.io/docs/manrs-public-api)
|
||||||
|
|
||||||
|
## Features:
|
||||||
|
- Query ROAs by ASN or country.
|
||||||
|
- Retrieve information about all known ASNs and their holders.
|
||||||
|
- Fetch data about Internet Exchange Points *(IXPs)*.
|
||||||
|
- Get conformance details for different entities participating in MANRS.
|
||||||
|
|
||||||
|
## How to Use:
|
||||||
|
**Note:** You must [request access](https://www.manrs.org/resources/api) to get an API key!
|
||||||
|
|
||||||
|
1. **Initialization**: Instantiate the `MANRS` class with your API key.
|
||||||
|
```python
|
||||||
|
import manrs
|
||||||
|
|
||||||
|
api = manrs.API('YOUR_API_KEY')
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Making Calls:** Use the provided methods to make calls to the MANRS API. For instance, to get ROAs by ASN:
|
||||||
|
```python
|
||||||
|
response = api.roa_by_asn('AS16661')
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Development Mode:** If you're working in a development environment, set the `dev` flag to `True` during initialization.
|
||||||
|
```
|
||||||
|
api = manrs.API('YOUR_API_KEY', dev=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
___
|
||||||
|
|
||||||
|
###### Mirrors
|
||||||
|
[acid.vegas](https://git.acid.vegas/manrs) • [GitHub](https://github.com/acidvegas/manrs) • [GitLab](https://gitlab.com/acidvegas/manrs) • [SuperNETs](https://git.supernets.org/acidvegas/manrs)
|
77
manrs.py
Normal file
77
manrs.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# MANRS API - developed by acidvegas in python (https://git.acid.vegas/manrs)
|
||||||
|
|
||||||
|
'''
|
||||||
|
Source : https://www.manrs.org/
|
||||||
|
Request API Access : https://www.manrs.org/resources/api
|
||||||
|
API Doumentation : https://manrs.stoplight.io/docs/manrs-public-api
|
||||||
|
'''
|
||||||
|
|
||||||
|
import http.client
|
||||||
|
|
||||||
|
class API(object):
|
||||||
|
def __init__(self, api_key: str, dev: bool=False):
|
||||||
|
'''
|
||||||
|
MANRS API class.
|
||||||
|
|
||||||
|
:param api_key: Your MANRS API key
|
||||||
|
:param dev: Whether or not to use the development API (default: False)
|
||||||
|
'''
|
||||||
|
self.api_key = api_key
|
||||||
|
self.dev = dev
|
||||||
|
|
||||||
|
def call(self, endpoint: str) -> dict:
|
||||||
|
'''
|
||||||
|
Makes a call to the MANRS API
|
||||||
|
|
||||||
|
:param endpoint: The endpoint you would like to query
|
||||||
|
'''
|
||||||
|
headers = {'Accept': 'application/json', 'Authorization': 'Bearer ' + self.api_key}
|
||||||
|
if not self.dev:
|
||||||
|
conn = http.client.HTTPSConnection('api.manrs.org')
|
||||||
|
else:
|
||||||
|
http.client.HTTPSConnection('api-dev.manrs.org')
|
||||||
|
conn.request('GET', endpoint, headers=headers)
|
||||||
|
res = conn.getresponse()
|
||||||
|
data = res.read()
|
||||||
|
return data.decode()
|
||||||
|
|
||||||
|
def roa_by_asn(self, asn: str) -> dict:
|
||||||
|
'''
|
||||||
|
Retrieve data about ROAs by ASN
|
||||||
|
|
||||||
|
:param asn: The ASN you would like to query either as a number or in AS12345 format
|
||||||
|
'''
|
||||||
|
return self.call('/roas/asn/'+asn)
|
||||||
|
|
||||||
|
def roa_by_country(self, country: str) -> dict:
|
||||||
|
'''
|
||||||
|
Retrieve ROAs by country
|
||||||
|
|
||||||
|
:param country: Two-letter ISO code for the country you wish to query
|
||||||
|
'''
|
||||||
|
return self.call('/roas/country/'+country)
|
||||||
|
|
||||||
|
def asn_info(self) -> dict:
|
||||||
|
'''Get a list of all known ASNs and info about them (e.g. holder name)'''
|
||||||
|
return self.call('/asns/info')
|
||||||
|
|
||||||
|
def ixp_info(self) -> dict:
|
||||||
|
'''Query for info on IXPs'''
|
||||||
|
return self.call('/ixps/info')
|
||||||
|
|
||||||
|
def conformance_by_cdn(self) -> dict:
|
||||||
|
'''List conformance for all CDNs that are participanting in MANRS'''
|
||||||
|
return self.call('/conformance/cdns')
|
||||||
|
|
||||||
|
def conformace_by_ixp(self) -> dict:
|
||||||
|
'''List conformance for all IXPs that are participanting in MANRS'''
|
||||||
|
return self.call('/conformance/ixps')
|
||||||
|
|
||||||
|
def conformance_by_network_operator(self) -> dict:
|
||||||
|
'''List conformance for all Network Operators that are participanting in MANRS'''
|
||||||
|
return self.call('/conformance/net-ops')
|
||||||
|
|
||||||
|
def conformance_by_vendor(self) -> dict:
|
||||||
|
'''List conformance for all equipment vendors that are participanting in MANRS'''
|
||||||
|
return self.call('/conformance/vendors')
|
Loading…
Reference in New Issue
Block a user