Skip to content

Instantly share code, notes, and snippets.

@RoninReilly
Created July 25, 2025 10:07
Show Gist options
  • Select an option

  • Save RoninReilly/355a0b0650406b6663ee3f883c9a47e7 to your computer and use it in GitHub Desktop.

Select an option

Save RoninReilly/355a0b0650406b6663ee3f883c9a47e7 to your computer and use it in GitHub Desktop.
🔍 Server Network Diagnostics - Check Firewall & Proxy Issues
#!/usr/bin/env python3
"""
🔍 ДИАГНОСТИКА СЕТЕВЫХ НАСТРОЕК СЕРВЕРА
Проверяет что может блокировать прокси
"""
import requests
import subprocess
import os
import sys
def check_basic_connectivity():
"""Проверяет базовую связность"""
print("🌐 Проверяю базовую связность...")
test_urls = [
"http://google.com",
"http://httpbin.org/ip",
"https://api.ipify.org",
"http://icanhazip.com"
]
for url in test_urls:
try:
response = requests.get(url, timeout=10)
print(f"✅ {url} - OK ({response.status_code})")
except Exception as e:
print(f"❌ {url} - FAIL: {e}")
def check_firewall():
"""Проверяет настройки firewall"""
print("\n🔥 Проверяю firewall...")
commands = [
"ufw status",
"iptables -L -n",
"netstat -tuln | grep :80",
"ss -tuln | grep :80"
]
for cmd in commands:
try:
result = subprocess.run(cmd.split(), capture_output=True, text=True, timeout=5)
print(f"\n📋 {cmd}:")
if result.stdout:
print(result.stdout[:500]) # Первые 500 символов
if result.stderr:
print(f"STDERR: {result.stderr[:200]}")
except Exception as e:
print(f"❌ {cmd} - FAIL: {e}")
def check_proxy_connectivity():
"""Проверяет работу через простой прокси"""
print("\n🔍 Проверяю работу через прокси...")
# Простые HTTP прокси для теста
test_proxies = [
"8.8.8.8:80",
"1.1.1.1:80",
"208.67.222.222:80"
]
for proxy in test_proxies:
try:
proxy_dict = {
'http': f'http://{proxy}',
'https': f'http://{proxy}'
}
response = requests.get(
"http://httpbin.org/ip",
proxies=proxy_dict,
timeout=5
)
print(f"✅ Прокси {proxy} - OK")
except Exception as e:
print(f"❌ Прокси {proxy} - FAIL: {e}")
def check_dns():
"""Проверяет DNS"""
print("\n🌐 Проверяю DNS...")
domains = ["google.com", "httpbin.org", "github.com"]
for domain in domains:
try:
result = subprocess.run(["nslookup", domain], capture_output=True, text=True, timeout=5)
if "NXDOMAIN" not in result.stdout:
print(f"✅ DNS {domain} - OK")
else:
print(f"❌ DNS {domain} - FAIL")
except Exception as e:
print(f"❌ DNS {domain} - FAIL: {e}")
def main():
print("🔍🔍🔍 ДИАГНОСТИКА СЕРВЕРА 🔍🔍🔍")
print("=" * 50)
check_basic_connectivity()
check_firewall()
check_proxy_connectivity()
check_dns()
print("\n" + "=" * 50)
print("🎯 РЕКОМЕНДАЦИИ:")
print("1. Если все базовые соединения работают, но прокси нет - проблема в firewall")
print("2. Попробуйте: sudo ufw allow out 80,443,8080,3128")
print("3. Или отключите firewall: sudo ufw disable")
print("4. Проверьте iptables: sudo iptables -F")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment