The internet here is very restricted and I want to...

创建于:2025年6月23日

使用 O3 回答 Chat01

问题

The internet here is very restricted and I want to make something like a VPN. I want to use Telegram proxies to access blocked site. Telegram has some proxies that actually work very well, but it’s only used for Telegram itself. I want to know if it’s possible to make a python script that tunnel everything through Telegram and from there, I can use telegram proxies to use as a VPN for my entire computer.

思考

Final answer breakdown

Telegram proxies aren’t a straightforward "one size fits all" solution:

  1. Quick answer: Only SOCKS5 proxies can route general traffic; MTProto is limited to Telegram.

  2. Explanation: There’s a need for clarification of the types of proxies.

  3. Approach 1: Use Telegram’s SOCKS5 proxies via OS settings or tools like proxychains to route traffic. A Python code snippet using PySocks could help.

  4. Approach 2: Set up a remote server running WireGuard, disguised behind MTProto.

  5. Limitations: Performance, privacy, and legal concerns to note.

Here's a simple Python snippet for using SOCKS5 proxies with Telegram:

python
#!/usr/bin/env python3 import socks, socket, threading, select LOCAL_LISTEN = ('127.0.0.1', 1080) REMOTE_PROXY = ('x.x.x.x', 1080) def handle(client): server = socks.socksocket() server.set_proxy(socks.SOCKS5, REMOTE_PROXY[0], REMOTE_PROXY[1]) try: server.connect(('0.0.0.0',0)) except Exception as e: client.close(); server.close(); return sockets = [client, server] while True: r, _, _ = select.select(sockets, [], []) if not r: break for s in r: data = s.recv(4096) if not data: client.close(); server.close(); return (server if s is client else client).sendall(data) sock Thought for 1m 9s

回答

Short answer

  • If a “Telegram proxy” is listed as SOCKS5, you can use it system-wide – the proxy is just an ordinary SOCKS5 server and any program (or a TUN-to-SOCKS bridge) can talk to it.
  • If it’s an MTProto proxy, you cannot use it like a VPN. MTProto proxies only understand Telegram’s own MTProto transport and will forward traffic only to Telegram’s data-centres. They drop any other packets, so the rest of the Internet never sees them. core.telegram.org
  • People who really need to hide a VPN sometimes wrap WireGuard or OpenVPN inside MTProto, but that requires running your own MTProto server and a small relay on the VPS – public Telegram proxies will not work. freefd.github.io

Below are the practical options and a minimal Python example.


1 Using Telegram SOCKS5 proxies as a “VPN”

Works only with proxies that Telegram labels “SOCKS5”.

What you needQuick how-to
A SOCKS5 proxy endpoint (host:port & optional user/pass). Public lists such as the GitHub repo hookzof/socks5_list often include many endpoints that Telegram clients use.Pick one that is actually reachable from your network.
A way to push all OS traffic into SOCKS5Linux / macOS: tun2socks (from go-tun2socks or clash) + a dummy TUN interface.<br>Windows: tools like ProxyCap, Proxifier or WinTun2Socks.
DNS leaksSet system DNS to something that also goes through the proxy (e.g. dnscrypt-proxy in “DNS-over-HTTPS via SOCKS5” mode).
<details> <summary>🖥️ Tiny proof-of-concept in Python (local SOCKS5 → upstream Telegram SOCKS5)</summary>
python
#!/usr/bin/env python3 """ Very small TCP forwarder that listens on 127.0.0.1:1081 and forwards every connection through a chosen Telegram SOCKS5 proxy. Point proxy-aware programs (or tun2socks) at 127.0.0.1:1081. """ import socket, threading, select, socks, sys LOCAL = ('127.0.0.1', 1081) TG_PROXY = ('203.0.113.77', 1080) # <- put your SOCKS5 host,port here def pump(src, dst): while True: data = src.recv(4096) if not data: break dst.sendall(data) def handle(client): remote = socks.socksocket() remote.set_proxy(socks.SOCKS5, *TG_PROXY) try: # first byte read from client tells us the target addr family etc. # we clone that connect via SOCKS5 BIND – omitted for brevity ↓ # see pySocks documentation for full implementation pass finally: client.close() remote.close() lsock = socket.socket() lsock.bind(LOCAL) lsock.listen(128) print(f'Local SOCKS bridge on {LOCAL}') while True: c, _ = lsock.accept() threading.Thread(target=handle, args=(c,), daemon=True).start()

This is only a skeleton (real code must parse the SOCKS handshake coming from the client), but it shows the idea: your programs speak to a local port; the script relays everything to the upstream Telegram SOCKS5. Combine it with tun2socks to capture the whole system’s traffic.

</details>

Pros & cons

✅ Pros❌ Cons
No server of your own required.SOCKS5 lists fluctuate; many hosts die quickly.
Easy to automate with Python or existing tools.No additional encryption – the proxy sees plain TLS/HTTP headers.
Works on any OS once the proxy address is set.Quality and speed are usually worse than paid VPNs.

2 Why MTProto proxies cannot become a VPN out-of-the-box

Telegram’s MTProto proxy is not a generic forwarder: it speaks the MTProto handshake, then tunnels encrypted Telegram messages to Telegram IPs only. The proxy never sees or forwards arbitrary TCP/UDP packets, so browsers, Steam, etc. just fail. core.telegram.org core.telegram.org

To bend MTProto to your will you’d need:

  1. A VPS you control.
  2. Your own MTProto proxy running in “fake-TLS” or “secure” mode on TCP/443.
  3. A second service (WireGuard, OpenVPN, Shadowsocks, etc.) running on the same VPS.
  4. A small userspace program that multiplexes the MTProto connection and forwards the VPN packets to the second service (some people use iptables + NFQUEUE, others patch mtproxy directly).
  5. Custom client software or a patched Telegram app on the computer so that it can inject the VPN packets into the MTProto stream.

The architecture above (WireGuard hidden behind MTProto) is described in community write-ups such as “Build your own VPN node with Traefik v2, MTProto proxy, WireGuard…” freefd.github.io. It does work, but it is a weekend-to-week-long DIY project, not a 20-line Python script, and public MTProto proxies cannot be used for step 2 because you must control the other end.


3 Recommendations

GoalEasiest route
Quick access to blocked websitesTry Telegram SOCKS5 proxies + tun2socks, or simply use Outline / V2Ray if you can rent a cheap VPS.
Stealth (“look like Telegram”)Rent a VPS and follow the MTProto + WireGuard approach; reuse existing open-source scripts instead of starting from scratch.
No server budgetPublic SOCKS5 lists are the only Telegram-based option, but expect instability.

Remember legality & ethics
Bypassing censorship can be illegal where you live; proxies and VPNs do not magically hide all fingerprints (DNS leaks, traffic patterns). Use trusted endpoints, add TLS/HTTPS where possible, and keep in mind that the proxy operator sees your IP and timing information even if they cannot read the encrypted payload.


TL;DR

  • SOCKS5 Telegram proxies = usable everywhere (just proxy your traffic).
  • MTProto Telegram proxies = Telegram-only; turning them into a full VPN means running your own server and complex tunnelling – not a simple Python one-liner.

分享这个问答