From add8088585491f49f3df5f254079776db054c3b9 Mon Sep 17 00:00:00 2001 From: Be Date: Thu, 29 Feb 2024 14:46:46 +0100 Subject: [PATCH] Add the AS Networks List Script --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++- as_network_list.py | 32 +++++++++++++++++++++++++++++ requirements.sh | 3 +++ requirements.txt | 5 +++++ 4 files changed, 89 insertions(+), 1 deletion(-) create mode 100755 as_network_list.py create mode 100755 requirements.sh create mode 100644 requirements.txt diff --git a/README.md b/README.md index ae3c675..49ac382 100644 --- a/README.md +++ b/README.md @@ -1 +1,49 @@ -# AS_Network_List \ No newline at end of file +# AS Prefixes List Script + +## Description + +* This Python script retrieves and prints the prefixes announced by a specified Autonomous System (AS). It uses the RIPE Stat Data API to fetch the data. + +* Tested only on MacOS and Linux :) + +## Installation + +1. Make sure you have Python 3 installed. You can download it from the [official website](https://www.python.org/downloads/). + +2. Clone this repository: + + ```bash + git clone https://github.com/C24Be/AS_Network_List.git + ``` + +3. Navigate to the repository folder: + + ```bash + cd AS_Network_List + ``` + +4. Install requirements: + + ```bash + ./requirements.sh + ``` + +## Usage + +1. Run the script with the AS number as an argument: + + ```bash + python ASList.py AS61280 + ``` + +2. If you want to disable all output except the prefixes, use the --quiet or -q switch: + + ```bash + python ASList.py AS61280 --quiet + ``` + +3. If you run the script with the -h or --help switch, it will print a help message: + + ```bash + python ASList.py --help + ``` diff --git a/as_network_list.py b/as_network_list.py new file mode 100755 index 0000000..68317a8 --- /dev/null +++ b/as_network_list.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 + +import requests +import argparse + +def get_as_prefixes(asn): + url = f"https://stat.ripe.net/data/announced-prefixes/data.json?resource={asn}" + response = requests.get(url) + if response.status_code == 200: + data = response.json() + prefixes = data['data']['prefixes'] + return [prefix['prefix'] for prefix in prefixes] + else: + return [] + +def main(): + parser = argparse.ArgumentParser(description='Get prefixes announced by an AS.') + parser.add_argument('asn', help='The AS number to get prefixes for.') + parser.add_argument('-q', '--quiet', action='store_true', help='Disable all output except prefixes.') + args = parser.parse_args() + + asn = args.asn + prefixes = get_as_prefixes(asn) + + if not args.quiet: + print(f"Prefixes announced by {asn}:") + + for prefix in prefixes: + print(prefix) + +if __name__ == "__main__": + main() diff --git a/requirements.sh b/requirements.sh new file mode 100755 index 0000000..564617a --- /dev/null +++ b/requirements.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +pip install -r requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6b16dbc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +certifi==2024.2.2 +charset-normalizer==3.3.2 +idna==3.6 +requests==2.31.0 +urllib3==2.2.1