mirror of
https://github.com/C24Be/AS_Network_List.git
synced 2026-01-24 23:26:38 +03:00
Add the AS Networks List Script
This commit is contained in:
50
README.md
50
README.md
@@ -1 +1,49 @@
|
||||
# AS_Network_List
|
||||
# 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
|
||||
```
|
||||
|
||||
32
as_network_list.py
Executable file
32
as_network_list.py
Executable file
@@ -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()
|
||||
3
requirements.sh
Executable file
3
requirements.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
pip install -r requirements.txt
|
||||
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
certifi==2024.2.2
|
||||
charset-normalizer==3.3.2
|
||||
idna==3.6
|
||||
requests==2.31.0
|
||||
urllib3==2.2.1
|
||||
Reference in New Issue
Block a user