# -*- coding: utf-8 -*-
#!/usr/bin/env python3
import socket
import time
from datetime import datetime
# ===== IP + LOCATION INFO =====
try:
import requests
HAS_REQUESTS = True
except:
HAS_REQUESTS = False
def get_network_info():
if not HAS_REQUESTS:
return {
"ip": "Unknown",
"country": "Unknown",
"region": "Unknown",
"city": "Unknown",
"isp": "Unknown"
}
urls = [
"https://ipapi.co/json/",
"http://ip-api.com/json/",
]
for url in urls:
try:
r = requests.get(url, timeout=4)
if r.status_code == 200:
d = r.json()
return {
"ip": d.get("ip", d.get("query", "Unknown")),
"country": d.get("country_name", d.get("country", "Unknown")),
"region": d.get("regionName", d.get("region", "Unknown")),
"city": d.get("city", "Unknown"),
"isp": d.get("org", "Unknown"),
}
except:
pass
return {
"ip": "Unknown",
"country": "Unknown",
"region": "Unknown",
"city": "Unknown",
"isp": "Unknown",
}
# ===== DNS PROVIDERS (UNCHANGED) =====
DNS_SERVERS = {
'Cloudflare': {'primary': '1.1.1.1', 'secondary': '1.0.0.1'},
'Google Public DNS': {'primary': '8.8.8.8', 'secondary': '8.8.4.4'},
'Quad9': {'primary': '9.9.9.9', 'secondary': '149.112.112.112'},
'OpenDNS Home': {'primary': '208.67.222.222', 'secondary': '208.67.220.220'},
'AdGuard DNS': {'primary': '94.140.14.14', 'secondary': '94.140.15.15'},
'Cloudflare for Families': {'primary': '1.1.1.2', 'secondary': '1.0.0.2'},
'Control D': {'primary': '76.76.2.0', 'secondary': '76.76.10.0'},
'NextDNS': {'primary': '45.90.28.0', 'secondary': '45.90.30.0'},
'CleanBrowsing': {'primary': '185.228.168.9', 'secondary': '185.228.169.9'},
'Level3': {'primary': '4.2.2.1', 'secondary': '4.2.2.2'},
'Comodo Secure DNS': {'primary': '8.26.56.26', 'secondary': '8.20.247.20'},
'DNS.Watch': {'primary': '84.200.69.80', 'secondary': '84.200.70.40'},
'Verisign': {'primary': '64.6.64.6', 'secondary': '64.6.65.6'},
'Alternate DNS': {'primary': '76.76.19.19', 'secondary': '76.223.122.150'},
'Ùn*énsørédDNS': {'primary': '91.239.100.100', 'secondary': '89.233.43.71'},
'Hurricane Electric': {'primary': '74.82.42.42', 'secondary': '66.220.18.42'},
'Gcore DNS': {'primary': '95.85.95.85', 'secondary': '2.56.220.2'},
'SafeDNS': {'primary': '195.46.39.39', 'secondary': '195.46.39.40'},
'OpenNIC': {'primary': '185.121.177.177', 'secondary': '169.239.202.202'},
'Yandex DNS': {'primary': '77.88.8.8', 'secondary': '77.88.8.1'},
'FreeDNS': {'primary': '37.235.1.174', 'secondary': '37.235.1.177'},
'Dyn DNS': {'primary': '216.146.35.35', 'secondary': '216.146.36.36'},
'Fourth Estate': {'primary': '45.77.165.194', 'secondary': '23.94.60.240'},
'Neustar': {'primary': '156.154.70.1', 'secondary': '156.154.71.1'},
'puntCAT': {'primary': '109.69.8.51', 'secondary': '109.69.8.52'},
}
# ===== TEST DOMAINS =====
GAME_DOMAINS = [
"mobilelegends.com",
"moonton.com",
"callofduty.com",
"activision.com",
"tencent.com",
"netease.com",
"cloudflare.com",
"googleapis.com",
"amazonaws.com",
]
# ===== TCP LATENCY =====
def tcp_latency(ip):
try:
start = time.perf_counter()
s = socket.create_connection((ip, 443), timeout=3)
s.close()
return (time.perf_counter() - start) * 1000
except: return None
# ===== DNS RESOLUTION =====
def dns_resolution(domain):
try:
start = time.perf_counter()
socket.gethostbyname(domain)
return (time.perf_counter() - start) * 1000
except: return None
# ===== MAIN UI =====
print("=" * 60)
print(" ADVANCED GAMING DNS OPTIMIZER (TERMUX SAFE)")
print(" Works for Mobile Legends / CODM / HoK / Bloodstrike")
print("=" * 60)
# Show network details
info = get_network_info()
print("\n YOUR NETWORK INFO")
print(f" IP Address: {info['ip']}")
print(f" Location : {info['city']}, {info['region']}, {info['country']}")
print(f" ISP : {info['isp']}")
print("=" * 60, "\n")
results = []
total = len(DNS_SERVERS)
idx = 0
for name, data in DNS_SERVERS.items():
idx += 1
print(f"[{idx}/{total}] Testing {name} ... ", end="")
primary = data["primary"]
tcp = tcp_latency(primary)
if not tcp:
print("Failed")
continue
dns_times = [dns_resolution(d) for d in GAME_DOMAINS if dns_resolution(d)]
if dns_times:
avg = sum(dns_times) / len(dns_times)
score = 100 - (tcp * 0.4 + avg * 0.6)
results.append((name, primary, data["secondary"], tcp, avg, score))
print(f"{tcp:.1f} ms / DNS {avg:.1f} ms")
else:
print("DNS failed")
# ===== RESULTS =====
print("\n\n========= RESULTS =========\n")
results.sort(key=lambda x: x[5], reverse=True)
for i, r in enumerate(results, 1):
print(f"{i}. {r[0]}")
print(f" Primary : {r[1]}")
print(f" Secondary : {r[2]}")
print(f" TCP : {r[3]:.1f} ms")
print(f" DNS : {r[4]:.1f} ms")
print(f" Score : {r[5]:.1f}/100\n")
if results:
best = results[0]
print(" BEST DNS FOR YOUR NETWORK")
print(f" {best[0]}")
print(f" {best[1]} / {best[2]}")
print("\n DONE ✔ You can close this window.\n")