Skip to content

Commit

Permalink
added github
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechromancer committed Apr 26, 2023
1 parent 698b8a7 commit c67a7ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 2 additions & 0 deletions cloudcheck/cloudcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand All @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions cloudcheck/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import zipfile
import requests
import ipaddress
import traceback
from pathlib import Path
from requests_cache import CachedSession
Expand Down Expand Up @@ -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

0 comments on commit c67a7ab

Please sign in to comment.