2017-12-29 15:39:52 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import json
|
2020-07-17 12:42:34 +02:00
|
|
|
|
2020-07-17 09:25:01 +02:00
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
2021-06-12 12:13:23 +02:00
|
|
|
from generator import download, download_to_file, get_version, write_to_file, get_abspath_source_file, consolidate_networks
|
2020-07-17 09:25:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_json_url(page):
|
|
|
|
soup = BeautifulSoup(page.text, 'html.parser')
|
|
|
|
retry_link_text = soup.find(class_='link-align')
|
|
|
|
retry_links = retry_link_text.find_all('a')
|
|
|
|
return retry_links[0].get('href')
|
|
|
|
|
|
|
|
|
2021-06-10 11:15:08 +02:00
|
|
|
def process(file, dst, name: str, description: str):
|
2020-07-17 09:25:01 +02:00
|
|
|
warninglist = {
|
2021-06-10 11:15:08 +02:00
|
|
|
'name': name,
|
2020-07-17 09:25:01 +02:00
|
|
|
'version': get_version(),
|
2021-06-10 11:15:08 +02:00
|
|
|
'description': description,
|
2020-07-17 09:25:01 +02:00
|
|
|
'matching_attributes': ["ip-src", "ip-dst", "domain|ip"],
|
|
|
|
'type': 'cidr'
|
|
|
|
}
|
2020-07-17 12:42:34 +02:00
|
|
|
|
2020-07-27 10:44:30 +02:00
|
|
|
with open(get_abspath_source_file(file), 'r') as json_file:
|
2020-07-17 09:25:01 +02:00
|
|
|
ms_azure_ip_list = json.load(json_file)
|
2020-07-17 12:42:34 +02:00
|
|
|
|
2021-06-10 11:15:08 +02:00
|
|
|
values = []
|
2020-07-17 09:25:01 +02:00
|
|
|
for value in ms_azure_ip_list['values']:
|
2021-06-10 11:15:08 +02:00
|
|
|
values += value['properties']['addressPrefixes']
|
|
|
|
|
2021-06-12 12:13:23 +02:00
|
|
|
warninglist['list'] = consolidate_networks(values)
|
2020-07-17 09:25:01 +02:00
|
|
|
|
2020-07-21 00:31:06 +02:00
|
|
|
write_to_file(warninglist, dst)
|
2020-07-17 09:25:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-06-10 11:15:08 +02:00
|
|
|
TYPES = [
|
|
|
|
{
|
|
|
|
"name": "List of known Microsoft Azure Datacenter IP Ranges",
|
|
|
|
"description": "Microsoft Azure Datacenter IP Ranges",
|
|
|
|
"url": "https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519",
|
|
|
|
"file": "ms-azure.json",
|
|
|
|
"destination_folder": "microsoft-azure",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "List of known Microsoft Azure US Government Cloud Datacenter IP Ranges",
|
|
|
|
"description": "Microsoft Azure US Government Cloud Datacenter IP Ranges",
|
|
|
|
"url": "https://www.microsoft.com/en-us/download/confirmation.aspx?id=57063",
|
|
|
|
"file": "ms-azure-us-gov.json",
|
|
|
|
"destination_folder": "microsoft-azure-us-gov",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "List of known Microsoft Azure Germany Datacenter IP Ranges",
|
|
|
|
"description": "Microsoft Azure Germany Datacenter IP Ranges",
|
|
|
|
"url": "https://www.microsoft.com/en-us/download/confirmation.aspx?id=57064",
|
|
|
|
"file": "ms-azure-germany.json",
|
|
|
|
"destination_folder": "microsoft-azure-germany",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "List of known Microsoft Azure China Datacenter IP Ranges",
|
|
|
|
"description": "Microsoft Azure China Datacenter IP Ranges",
|
|
|
|
"url": "https://www.microsoft.com/en-us/download/confirmation.aspx?id=57062",
|
|
|
|
"file": "ms-azure-china.json",
|
|
|
|
"destination_folder": "microsoft-azure-china",
|
|
|
|
}
|
|
|
|
]
|
2020-07-17 09:25:01 +02:00
|
|
|
|
2021-06-10 11:15:08 +02:00
|
|
|
for type in TYPES:
|
|
|
|
ms_azure_json_url = get_json_url(download(type["url"]))
|
|
|
|
download_to_file(ms_azure_json_url, type["file"])
|
|
|
|
process(type["file"], type["destination_folder"], type["name"], type["description"])
|