Guest User

Untitled

a guest
Dec 8th, 2025
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.57 KB | None | 0 0
  1. import socket
  2. import ssl
  3. import requests
  4. import time
  5. from urllib.parse import urlparse
  6.  
  7. def test_access(url, timeout=5):
  8.     """Проверяет: DNS → TCP handshake → TLS handshake → HTTP GET"""
  9.     parsed = urlparse(url)
  10.     host = parsed.hostname
  11.     port = parsed.port or (443 if parsed.scheme == 'https' else 80)
  12.    
  13.     # 1. DNS
  14.     try:
  15.         ip = socket.gethostbyname(host)
  16.         dns_ok = True
  17.     except Exception as e:
  18.         return {'url': url, 'dns': False, 'tcp': False, 'tls': False, 'http': False, 'error': f'DNS: {e}'}
  19.  
  20.     # 2. TCP handshake
  21.     try:
  22.         with socket.create_connection((host, port), timeout=timeout) as sock:
  23.             tcp_ok = True
  24.     except Exception as e:
  25.         return {'url': url, 'dns': True, 'tcp': False, 'tls': False, 'http': False, 'error': f'TCP: {e}'}
  26.  
  27.     # 3. TLS handshake (без отправки HTTP)
  28.     try:
  29.         context = ssl.create_default_context()
  30.         with socket.create_connection((host, port), timeout=timeout) as sock:
  31.             with context.wrap_socket(sock, server_hostname=host) as ssock:
  32.                 tls_ok = True
  33.     except Exception as e:
  34.         return {'url': url, 'dns': True, 'tcp': True, 'tls': False, 'http': False, 'error': f'TLS: {e}'}
  35.  
  36.     # 4. HTTP GET
  37.     try:
  38.         r = requests.get(url, timeout=timeout, verify=True)
  39.         return {
  40.             'url': url,
  41.             'dns': True,
  42.             'tcp': True,
  43.             'tls': True,
  44.             'http': True,
  45.             'status': r.status_code,
  46.             'title': r.text[:200].split('<title>')[-1].split('</title>')[0] if '<title>' in r.text else ''
  47.         }
  48.     except Exception as e:
  49.         return {'url': url, 'dns': True, 'tcp': True, 'tls': True, 'http': False, 'error': f'HTTP: {e}'}
  50.  
  51. # Набор контрольных сайтов:
  52. # - гарантированно «белые» (должны открываться)
  53. # - заведомо легальные, но «левые» (как click-watch.com)
  54. # - заведомо заблокированные (для сравнения)
  55.  
  56. test_urls = [
  57.     "https://yandex.ru",                     # «белый», российский
  58.     "https://google.com",                    # «серый», но пока работает
  59.     "https://click-watch.com",               # ваш сайт — малотрафиковый, HK, легальный
  60.     "https://github.com",                    # технический, часто «на грани»
  61.     "https://archive.org",                  # часто блокируют DPI
  62.     "https://www.bbc.com",                  # иностранный СМИ — может быть в чёрном списке
  63. ]
  64.  
  65. print("🔍 Тест доступа по уровням (DNS → TCP → TLS → HTTP)\n")
  66.  
  67. for url in test_urls:
  68.     res = test_access(url)
  69.     status = "✅ OK" if res['http'] else "❌ FAIL"
  70.     details = f"DNS:{int(res['dns'])} TCP:{int(res['tcp'])} TLS:{int(res['tls'])} HTTP:{int(res['http'])}"
  71.     error = f" | {res.get('error', '')}" if not res['http'] else f" | {res.get('status', '')}"
  72.     print(f"{status:<8} {url:<25} {details}{error}")
  73.  
  74. print("\n📌 Интерпретация:")
  75. print("— Если DNS и TCP работают, а TLS/HTTP падают — это DPI/SNI-блокировка (признак whitelist-режима).")
  76. print("— Если DNS не разрешается — DNS-блокировка (часто у провайдеров).")
  77. print("— Если у click-watch.com: DNS+TCP=OK, но TLS/HTTP=FAIL → это НЕ ваша паранойя.")
Advertisement
Add Comment
Please, Sign In to add comment