commit 1869936ca45ddd1c00089f7c2a678f2e0579f503 Author: Nick Bouwhuis Date: Sat Mar 4 22:02:15 2023 +0100 first commit diff --git a/check_as_path.py b/check_as_path.py new file mode 100644 index 0000000..f20eb23 --- /dev/null +++ b/check_as_path.py @@ -0,0 +1,29 @@ +import requests +import argparse +import sys + +def check_as_path(prefix, as_to_check): + url = f'https://stat.ripe.net/data/looking-glass/data.json?resource={prefix}' + response = requests.get(url) + if response.ok: + data = response.json() + for rrc in data['data']['rrcs']: + for peer in rrc['peers']: + as_path = peer['as_path'] + if as_to_check in as_path: + print(f"CRITICAL: AS {as_to_check} found in AS path for prefix {prefix} at RRC {rrc['rrc']}") + return 2 # return critical + print(f"OK: AS {as_to_check} not found in AS path for prefix {prefix}") + return 0 # return OK + else: + print(f"UNKNOWN: Error fetching data from {url}") + return 3 # return unknown + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Check if a certain AS is in the AS path for any peers for a given prefix') + parser.add_argument('--prefix', required=True, help='IPv4 prefix to check') + parser.add_argument('--asn', required=True, help='AS number to check for') + args = parser.parse_args() + exit_code = check_as_path(args.prefix, args.asn) + sys.exit(exit_code) +