File size: 9,252 Bytes
b190b45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env python3
"""

Restricted APIs Configuration

تنظیمات APIهایی که نیاز به Proxy/DNS دارن



فقط APIهایی که واقعاً فیلتر شدن یا محدودیت دارن

"""

from typing import Dict, List
from enum import Enum


class AccessLevel(Enum):
    """سطح دسترسی"""
    DIRECT = "direct"  # مستقیم (بدون proxy/DNS)
    SMART = "smart"    # هوشمند (با fallback)
    FORCE_PROXY = "force_proxy"  # حتماً با proxy
    FORCE_DNS = "force_dns"  # حتماً با DNS


# ✅ APIهایی که به Proxy/DNS نیاز دارن
RESTRICTED_APIS = {
    # ─────────────────────────────────────────────────────────
    # 🔴 CRITICAL: حتماً نیاز به Proxy/DNS دارن
    # ─────────────────────────────────────────────────────────
    "kucoin": {
        "domains": [
            "api.kucoin.com",
            "api-futures.kucoin.com",
            "openapi-v2.kucoin.com"
        ],
        "access_level": AccessLevel.SMART,
        "priority": 1,
        "reason": "Critical exchange - always use smart access with rotating DNS/Proxy",
        "fallback_order": ["direct", "dns_cloudflare", "dns_google", "proxy", "dns_proxy"],
        "rotate_dns": True,  # چرخش DNS برای امنیت بیشتر
        "rotate_proxy": True,  # چرخش Proxy
        "always_secure": True  # همیشه امن
    },
    
    "binance": {
        "domains": [
            "api.binance.com",
            "api1.binance.com",
            "api2.binance.com",
            "api3.binance.com",
            "fapi.binance.com"
        ],
        "access_level": AccessLevel.SMART,  # همیشه Smart Access
        "priority": 1,
        "reason": "Critical exchange - always use smart access with rotating DNS/Proxy",
        "fallback_order": ["direct", "dns_cloudflare", "dns_google", "proxy", "dns_proxy"],
        "rotate_dns": True,  # چرخش DNS برای امنیت بیشتر
        "rotate_proxy": True,  # چرخش Proxy
        "always_secure": True  # همیشه امن
    },
    
    "bybit": {
        "domains": [
            "api.bybit.com",
            "api-testnet.bybit.com"
        ],
        "access_level": AccessLevel.SMART,
        "priority": 2,
        "reason": "May have regional restrictions",
        "fallback_order": ["direct", "dns_cloudflare", "proxy"]
    },
    
    "okx": {
        "domains": [
            "www.okx.com",
            "aws.okx.com"
        ],
        "access_level": AccessLevel.SMART,
        "priority": 2,
        "reason": "Geo-restrictions in some regions",
        "fallback_order": ["direct", "dns_google", "proxy"]
    },
    
    # ─────────────────────────────────────────────────────────
    # 🟡 MEDIUM: ممکنه نیاز داشته باشن
    # ─────────────────────────────────────────────────────────
    "coinmarketcap_pro": {
        "domains": [
            "pro-api.coinmarketcap.com"
        ],
        "access_level": AccessLevel.DIRECT,  # فعلاً مستقیم کافیه
        "priority": 3,
        "reason": "Usually works directly with API key",
        "fallback_order": ["direct", "dns_cloudflare"]
    },
}


# ✅ APIهایی که مستقیم کار می‌کنن (نیازی به Proxy/DNS ندارن)
UNRESTRICTED_APIS = {
    "coingecko": {
        "domains": [
            "api.coingecko.com",
            "pro-api.coingecko.com"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Works globally without restrictions"
    },
    
    "coinpaprika": {
        "domains": [
            "api.coinpaprika.com"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Free API, no restrictions"
    },
    
    "coincap": {
        "domains": [
            "api.coincap.io"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Free API, globally accessible"
    },
    
    "coinlore": {
        "domains": [
            "api.coinlore.net"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Free API, no geo-restrictions"
    },
    
    "cryptopanic": {
        "domains": [
            "cryptopanic.com"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "News API, works globally"
    },
    
    "alternative_me": {
        "domains": [
            "api.alternative.me"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Fear & Greed index, no restrictions"
    },
    
    "blockchain_info": {
        "domains": [
            "blockchain.info"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Public blockchain explorer"
    },
    
    "etherscan": {
        "domains": [
            "api.etherscan.io"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Public API with key"
    },
    
    "bscscan": {
        "domains": [
            "api.bscscan.com"
        ],
        "access_level": AccessLevel.DIRECT,
        "reason": "Public API with key"
    },
}


def get_access_config(domain: str) -> Dict:
    """

    دریافت تنظیمات دسترسی برای یک domain

    

    Returns:

        {

            "access_level": AccessLevel,

            "use_smart_access": bool,

            "fallback_order": List[str]

        }

    """
    # جستجو در Restricted APIs
    for api_name, config in RESTRICTED_APIS.items():
        if domain in config["domains"]:
            return {
                "api_name": api_name,
                "access_level": config["access_level"],
                "use_smart_access": config["access_level"] != AccessLevel.DIRECT,
                "fallback_order": config.get("fallback_order", ["direct"]),
                "priority": config.get("priority", 99),
                "reason": config.get("reason", "")
            }
    
    # جستجو در Unrestricted APIs
    for api_name, config in UNRESTRICTED_APIS.items():
        if domain in config["domains"]:
            return {
                "api_name": api_name,
                "access_level": config["access_level"],
                "use_smart_access": False,
                "fallback_order": ["direct"],
                "priority": 99,
                "reason": config.get("reason", "")
            }
    
    # Default: استفاده از Smart Access
    return {
        "api_name": "unknown",
        "access_level": AccessLevel.SMART,
        "use_smart_access": True,
        "fallback_order": ["direct", "dns_cloudflare", "proxy"],
        "priority": 50,
        "reason": "Unknown API, using smart access"
    }


def should_use_smart_access(url: str) -> bool:
    """

    آیا این URL نیاز به Smart Access داره؟

    """
    # استخراج domain از URL
    if "://" in url:
        domain = url.split("://")[1].split("/")[0]
    else:
        domain = url.split("/")[0]
    
    config = get_access_config(domain)
    return config["use_smart_access"]


def get_restricted_apis_list() -> List[str]:
    """لیست APIهایی که نیاز به Proxy/DNS دارن"""
    return list(RESTRICTED_APIS.keys())


def get_unrestricted_apis_list() -> List[str]:
    """لیست APIهایی که مستقیم کار می‌کنن"""
    return list(UNRESTRICTED_APIS.keys())


def get_all_monitored_domains() -> List[str]:
    """همه domainهایی که تحت نظارت هستن"""
    domains = []
    
    for config in RESTRICTED_APIS.values():
        domains.extend(config["domains"])
    
    for config in UNRESTRICTED_APIS.values():
        domains.extend(config["domains"])
    
    return domains


def print_config_summary():
    """چاپ خلاصه تنظیمات"""
    print("=" * 60)
    print("📋 RESTRICTED APIS CONFIGURATION")
    print("=" * 60)
    
    print("\n🔴 APIs that need Proxy/DNS:")
    for api_name, config in RESTRICTED_APIS.items():
        print(f"\n  {api_name.upper()}:")
        print(f"    Domains: {', '.join(config['domains'])}")
        print(f"    Access: {config['access_level'].value}")
        print(f"    Priority: {config['priority']}")
        print(f"    Reason: {config['reason']}")
    
    print("\n\n✅ APIs that work DIRECT:")
    for api_name, config in UNRESTRICTED_APIS.items():
        print(f"  • {api_name}: {config['domains'][0]}")
    
    print("\n" + "=" * 60)
    print(f"Total Restricted: {len(RESTRICTED_APIS)}")
    print(f"Total Unrestricted: {len(UNRESTRICTED_APIS)}")
    print("=" * 60)


if __name__ == "__main__":
    print_config_summary()