commit e12d10a1b12677caee808c24957dc62e0337eeda Author: mikhail Date: Wed Feb 26 20:50:02 2025 -0500 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b694934 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..7370f73 --- /dev/null +++ b/main.py @@ -0,0 +1,84 @@ +import requests +import time +from dataclasses import dataclass +from pathlib import Path +from typing import Any, Final + +GET_ACCESS_TOKEN_URL: Final[str] = ( + "https://api-pro.ducunt.com/rest/v1/security/tokens/accs" +) + +get_access_token_payload: dict[str, str | dict[str, str]] = { + "clientApp": {"name": "URBAN_VPN_BROWSER_EXTENSION"}, + "type": "accs", +} + +with requests.post( + GET_ACCESS_TOKEN_URL, + json=get_access_token_payload, + headers={"Authorization": "Bearer On9GLm0c8B5GFWI9FYtdfPWlXfjhpF0Q"}, +) as request: + security_token_payload: Any = request.json() + +authentication_token: str = security_token_payload["value"] + +GET_COUNTRIES_URL: Final[str] = ( + "https://stats.ducunt.com/api/rest/v2/entrypoints/countries" +) + +with requests.get( + GET_COUNTRIES_URL, + headers={ + "X-Client-App": "URBAN_VPN_BROWSER_EXTENSION", + "Authorization": f"Bearer {authentication_token}", + }, +) as request: + countries_payload: Any = request.json() + +hosts: list[Any] = [ + element["servers"]["elements"] + for element in countries_payload["countries"]["elements"] + if element["servers"]["count"] > 0 +] + + +@dataclass +class Host: + ip: str + port: str + signature: str + + +host_data: list[Host] = [ + Host( + ip=element["address"]["primary"]["host"], + port=element["address"]["primary"]["port"], + signature=element["signature"] if "signature" in element else "", + ) + for host in hosts + for element in host +] +GET_ACCESS_PROXY_URL: Final[str] = ( + "https://api-pro.ducunt.com/rest/v1/security/tokens/accs-proxy" +) + +with Path("proxies").open("w", encoding="utf-8") as proxy_file: + for host in host_data: + + get_access_proxy_token_payload: dict[str, str | dict[str, str]] = { + "clientApp": {"name": "URBAN_VPN_BROWSER_EXTENSION"}, + "signature": next( + (host.signature for host in host_data if len(host.signature) > 0), "" + ), + "type": "accs", + } + + with requests.post( + GET_ACCESS_PROXY_URL, + json=get_access_proxy_token_payload, + headers={"Authorization": f"Bearer {authentication_token}"}, + ) as request: + response: Any = request.json() + time.sleep(0.25) + + proxy_file.write(f"http://{response['value']}:1@{host.ip}:{host.port}\n") diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ef487e0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +requests==2.32.3 \ No newline at end of file