Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import ssl
- import requests
- import time
- from urllib.parse import urlparse
- def test_access(url, timeout=5):
- """Проверяет: DNS → TCP handshake → TLS handshake → HTTP GET"""
- parsed = urlparse(url)
- host = parsed.hostname
- port = parsed.port or (443 if parsed.scheme == 'https' else 80)
- # 1. DNS
- try:
- ip = socket.gethostbyname(host)
- dns_ok = True
- except Exception as e:
- return {'url': url, 'dns': False, 'tcp': False, 'tls': False, 'http': False, 'error': f'DNS: {e}'}
- # 2. TCP handshake
- try:
- with socket.create_connection((host, port), timeout=timeout) as sock:
- tcp_ok = True
- except Exception as e:
- return {'url': url, 'dns': True, 'tcp': False, 'tls': False, 'http': False, 'error': f'TCP: {e}'}
- # 3. TLS handshake (без отправки HTTP)
- try:
- context = ssl.create_default_context()
- with socket.create_connection((host, port), timeout=timeout) as sock:
- with context.wrap_socket(sock, server_hostname=host) as ssock:
- tls_ok = True
- except Exception as e:
- return {'url': url, 'dns': True, 'tcp': True, 'tls': False, 'http': False, 'error': f'TLS: {e}'}
- # 4. HTTP GET
- try:
- r = requests.get(url, timeout=timeout, verify=True)
- return {
- 'url': url,
- 'dns': True,
- 'tcp': True,
- 'tls': True,
- 'http': True,
- 'status': r.status_code,
- 'title': r.text[:200].split('<title>')[-1].split('</title>')[0] if '<title>' in r.text else ''
- }
- except Exception as e:
- return {'url': url, 'dns': True, 'tcp': True, 'tls': True, 'http': False, 'error': f'HTTP: {e}'}
- # Набор контрольных сайтов:
- # - гарантированно «белые» (должны открываться)
- # - заведомо легальные, но «левые» (как click-watch.com)
- # - заведомо заблокированные (для сравнения)
- test_urls = [
- "https://yandex.ru", # «белый», российский
- "https://google.com", # «серый», но пока работает
- "https://click-watch.com", # ваш сайт — малотрафиковый, HK, легальный
- "https://github.com", # технический, часто «на грани»
- "https://archive.org", # часто блокируют DPI
- "https://www.bbc.com", # иностранный СМИ — может быть в чёрном списке
- ]
- print("🔍 Тест доступа по уровням (DNS → TCP → TLS → HTTP)\n")
- for url in test_urls:
- res = test_access(url)
- status = "✅ OK" if res['http'] else "❌ FAIL"
- details = f"DNS:{int(res['dns'])} TCP:{int(res['tcp'])} TLS:{int(res['tls'])} HTTP:{int(res['http'])}"
- error = f" | {res.get('error', '')}" if not res['http'] else f" | {res.get('status', '')}"
- print(f"{status:<8} {url:<25} {details}{error}")
- print("\n📌 Интерпретация:")
- print("— Если DNS и TCP работают, а TLS/HTTP падают — это DPI/SNI-блокировка (признак whitelist-режима).")
- print("— Если DNS не разрешается — DNS-блокировка (часто у провайдеров).")
- print("— Если у click-watch.com: DNS+TCP=OK, но TLS/HTTP=FAIL → это НЕ ваша паранойя.")
Advertisement
Add Comment
Please, Sign In to add comment