diff --git a/README.md b/README.md index aef47aa..ef5ab9b 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,4 @@ print(subnet) # IPv4Network('168.62.0.0/19') - DigitalOcean ([source](http://digitalocean.com/geo/google.csv)) - Cloudflare ([source](https://api.cloudflare.com/client/v4/ips)) - Akamai ([source](https://techdocs.akamai.com/property-manager/pdfs/akamai_ipv4_ipv6_CIDRs-txt.zip)) +- Github ([source](https://api.github.com/meta)) diff --git a/cloudcheck/cloudcheck.py b/cloudcheck/cloudcheck.py index 4f6e56a..defba45 100644 --- a/cloudcheck/cloudcheck.py +++ b/cloudcheck/cloudcheck.py @@ -3,6 +3,7 @@ import traceback from threading import Lock from datetime import datetime +from collections import OrderedDict from concurrent.futures import ThreadPoolExecutor from .providers import * @@ -29,6 +30,7 @@ def __init__(self, *args, **kwargs): with ThreadPoolExecutor(max_workers=len(provider_classes)) as e: for p in provider_classes: e.submit(self._get_provider, p, *args, **kwargs) + self.providers = OrderedDict(sorted(self.providers.items())) def _get_provider(self, p, *args, **kwargs): try: diff --git a/cloudcheck/providers.py b/cloudcheck/providers.py index db85787..74a7f9c 100644 --- a/cloudcheck/providers.py +++ b/cloudcheck/providers.py @@ -3,6 +3,7 @@ import logging import zipfile import requests +import ipaddress import traceback from pathlib import Path from requests_cache import CachedSession @@ -149,3 +150,21 @@ def parse_response(self, response): if line: ranges.add(line) return ranges + + +class Github(CloudProvider): + main_url = "https://api.github.com/meta" + provider_type = "cdn" + + def parse_response(self, response): + ranges = set() + response_json = response.json() + for k, v in response_json.items(): + if isinstance(v, list): + for n in v: + try: + net = ipaddress.ip_network(n) + ranges.add(n) + except ValueError: + pass + return ranges