Skip to content

Instantly share code, notes, and snippets.

@AmirSbss
Last active August 31, 2020 14:46
Show Gist options
  • Save AmirSbss/b6760bbf24e7099358a909068288f662 to your computer and use it in GitHub Desktop.
Save AmirSbss/b6760bbf24e7099358a909068288f662 to your computer and use it in GitHub Desktop.
Telegram MTProxy link validator
from urllib import parse
import string
import base64
import traceback
def validate(proxy_link):
try:
if proxy_link.startswith("tg://proxy") or proxy_link.replace("https://", "").startswith("t.me/proxy"):
args = dict(parse.parse_qsl(parse.urlsplit(proxy_link).query))
if args.get("server") and args.get("port") and args.get("secret"):
if args.get("port").isnumeric():
secret = args.get("secret").replace("-", "+").replace("_", "/")
if not all(c in string.hexdigits for c in secret):
try:
if not secret.endswith("="):
secret += "=="
secret = base64.b64decode(secret).hex()
except Exception as e:
try:
secret += "="
secret = base64.b64decode(secret).hex()
except Exception as e:
pass
if all(c in string.hexdigits for c in secret):
if (secret.startswith("ee") and len(secret) > 34) or (
secret.startswith("dd") and len(secret) == 34) or (len(secret) == 32):
return True
return False
except:
traceback.print_exc()
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment