-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added my python API class #16
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ISC License | ||
|
||
Copyright (c) 2023, acidvegas <[email protected]> | ||
|
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line length |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's a pylint line length limit of 80 chars. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you telling me my lines have to be 80 chars to be approved for merging, or just suggesting it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm saying that the python linter is going to complain, so it'd sure be nicer if it didn't complain. |
||
''' | ||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line length |
||
'''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''' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line length |
||
return self.call('/conformance/vendors') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason you picked ISC instead of apache2 here?