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
|
|
|
|
|
2020-07-27 10:44:30 +02:00
|
|
|
from generator import download, download_to_file, get_version, write_to_file, get_abspath_source_file
|
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')
|
|
|
|
|
|
|
|
|
|
|
|
def process(file, dst):
|
|
|
|
|
|
|
|
warninglist = {
|
|
|
|
'name': 'List of known Microsoft Azure Datacenter IP Ranges',
|
|
|
|
'version': get_version(),
|
|
|
|
'description': 'Microsoft Azure Datacenter IP Ranges',
|
|
|
|
'list': [],
|
|
|
|
'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
|
|
|
|
2020-07-17 09:25:01 +02:00
|
|
|
for value in ms_azure_ip_list['values']:
|
|
|
|
warninglist['list'] += value['properties']['addressPrefixes']
|
|
|
|
|
2020-07-21 00:31:06 +02:00
|
|
|
write_to_file(warninglist, dst)
|
2020-07-17 09:25:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
ms_azure_url = 'https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519'
|
|
|
|
ms_azure_file = 'ms-azure.json'
|
|
|
|
ms_azure_dst = 'microsoft-azure'
|
|
|
|
|
|
|
|
ms_azure_json_url = get_json_url(download(ms_azure_url))
|
|
|
|
download_to_file(ms_azure_json_url, ms_azure_file)
|
2020-07-17 12:42:34 +02:00
|
|
|
process(ms_azure_file, ms_azure_dst)
|