manrs- python class for the manrs api |
git clone git://git.acid.vegas/manrs.git |
Log | Files | Refs | Archive | README | LICENSE |
manrs.py (2353B)
1 #!/usr/bin/env python 2 # MANRS API - developed by acidvegas in python (https://git.acid.vegas/manrs) 3 4 ''' 5 Source : https://www.manrs.org/ 6 Request API Access : https://www.manrs.org/resources/api 7 API Doumentation : https://manrs.stoplight.io/docs/manrs-public-api 8 ''' 9 10 import http.client 11 12 class API(object): 13 def __init__(self, api_key: str, dev: bool=False): 14 ''' 15 MANRS API class. 16 17 :param api_key: Your MANRS API key 18 :param dev: Whether or not to use the development API (default: False) 19 ''' 20 self.api_key = api_key 21 self.dev = dev 22 23 def call(self, endpoint: str) -> dict: 24 ''' 25 Makes a call to the MANRS API 26 27 :param endpoint: The endpoint you would like to query 28 ''' 29 headers = {'Accept': 'application/json', 'Authorization': 'Bearer ' + self.api_key} 30 if not self.dev: 31 conn = http.client.HTTPSConnection('api.manrs.org') 32 else: 33 conn = http.client.HTTPSConnection('api-dev.manrs.org') 34 conn.request('GET', endpoint, headers=headers) 35 res = conn.getresponse() 36 data = res.read() 37 return data.decode() 38 39 def roa_by_asn(self, asn: str) -> dict: 40 ''' 41 Retrieve data about ROAs by ASN 42 43 :param asn: The ASN you would like to query either as a number or in AS12345 format 44 ''' 45 return self.call('/roas/asn/'+asn) 46 47 def roa_by_country(self, country: str) -> dict: 48 ''' 49 Retrieve ROAs by country 50 51 :param country: Two-letter ISO code for the country you wish to query 52 ''' 53 return self.call('/roas/country/'+country) 54 55 def asn_info(self) -> dict: 56 '''Get a list of all known ASNs and info about them (e.g. holder name)''' 57 return self.call('/asns/info') 58 59 def ixp_info(self) -> dict: 60 '''Query for info on IXPs''' 61 return self.call('/ixps/info') 62 63 def conformance_by_cdn(self) -> dict: 64 '''List conformance for all CDNs that are participanting in MANRS''' 65 return self.call('/conformance/cdns') 66 67 def conformace_by_ixp(self) -> dict: 68 '''List conformance for all IXPs that are participanting in MANRS''' 69 return self.call('/conformance/ixps') 70 71 def conformance_by_network_operator(self) -> dict: 72 '''List conformance for all Network Operators that are participanting in MANRS''' 73 return self.call('/conformance/net-ops') 74 75 def conformance_by_vendor(self) -> dict: 76 '''List conformance for all equipment vendors that are participanting in MANRS''' 77 return self.call('/conformance/vendors')