-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws.py
More file actions
38 lines (31 loc) · 923 Bytes
/
Copy pathaws.py
File metadata and controls
38 lines (31 loc) · 923 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import ipaddress
from wreq import Jar, Cookie
from wreq.blocking import Client
from wreq.emulation import Emulation
from wreq.exceptions import *
from wreq.header import HeaderMap
class AWS:
def check(self, ip: str) -> bool:
ip = ipaddress.ip_address(ip)
for prefix in self.ranges["prefixes"]:
if ip.version == 4 and ip in ipaddress.ip_network(prefix["ip_prefix"]):
return prefix
for prefix in self.ranges["ipv6_prefixes"]:
if ip.version == 6 and ip in ipaddress.ip_network(prefix["ipv6_prefix"]):
return prefix
return False
def __init__(
self,
emulation = Emulation.Firefox147,
headers: dict = {},
):
self.headers = HeaderMap()
for k, v in headers.items():
self.headers[k] = v
self.client = Client(
emulation = emulation,
headers = self.headers
)
r = self.client.get("https://ip-ranges.amazonaws.com/ip-ranges.json")
r.raise_for_status()
self.ranges = r.json()