logo
0
0
WeChat Login
uk0<zhangjianxinnet@gmail.com>
CI: add Windows 7 builds using go-legacy-win7 fork (Go 1.26 with Win7 support)

STUN Max Logo

微信公众号:你起来我讲两句

WeChat QR Code

STUN Max

P2P TCP tunnel with STUN hole punching and automatic server relay fallback.
Cross-platform GUI + CLI. Zero configuration networking.


Features

  • P2P Direct Connection — STUN hole punch with Birthday Attack (256 sockets) + port prediction (±1000), data never touches the server
  • Auto Relay Fallback — If P2P fails, seamlessly falls back to server relay; background retry upgrades back to P2P
  • NAT Traversal — Detects NAT1 (Cone) / NAT4 (Symmetric), adapts punch strategy; ~98% success for NAT3+NAT4 pairs
  • gVisor TCP/IP Stack — Production-grade userspace TCP (same as Tailscale/tun2socks) for VPN proxy and port forwarding
  • TUN VPN — Full subnet routing with SNAT, multi-VPN support (multiple peers simultaneously), VPN auto-restore on reconnect
  • Port Forwarding — Map any remote peer's host:port to your localhost, with gVisor reliable transport
  • Speed Test — P2P bandwidth test with cancel support and real-time progress
  • File Transfer — Send files with compression, CRC verification, rate-limited P2P UDP, auto relay fallback
  • Proxy Bypass — Auto-detects physical NIC, bypasses TUN proxies (Clash/V2Ray), skips CGNAT ranges
  • LAN Auto-Detection — Same public IP peers connect via local address (zero latency)
  • Auto Reconnect — Network changes trigger reconnect with backoff (1s→5s), P2P + VPN auto-restore
  • Room Management — Client-created rooms auto-delete when owner leaves; dashboard rooms persist; per-room relay control
  • GUI + CLI — Gio UI desktop app (Windows/Mac/Android) + readline CLI with tab completion
  • Android App — Full-featured with VPN, auto permission, native icon, WiFi-priority networking
  • Server Dashboard — Room management, peer monitoring, IP geolocation, STUN stats, Kick/Ban, relay control
  • NAT Diagnosticnatcheck tool with RFC 5780 support, Chinese UI, proxy bypass, comprehensive report
  • E2E Encryption — X25519 + XChaCha20-Poly1305, thread-safe, 24-byte nonce
  • SQLite Persistence — Rooms and blacklists survive server restart
  • Self-Hosted STUN — Lightweight STUN server with HTTP stats API

Architecture

┌──────────┐ 1. UDP hole punch ┌──────────┐ │ Client A │◄ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ►│ Client B │ │ (GUI/CLI)│ 2. P2P UDP direct │ (GUI/CLI)│ │ │◄══════════════════════════►│ │ └────┬─────┘ (gVisor TCP/IP stack) └────┬─────┘ │ │ │ WebSocket (signaling + relay) │ └───────────────┬───────────────────────┘ │ ┌──────┴──────┐ │ Server │ │ Signal+Relay│ │ + Dashboard │ └─────────────┘

Connection flow:

  1. Both clients connect to signal server via WebSocket
  2. STUN discovery finds public IP:port (supports custom/self-hosted STUN)
  3. UDP hole punch with Birthday Attack + port prediction
  4. Data flows over P2P UDP — server not in the data path
  5. gVisor userspace TCP/IP stack handles congestion control, retransmission, SACK
  6. If punch fails 5 times → auto relay, background retry continues
  7. If P2P later succeeds → auto upgrade back from relay

Screenshots

DashboardGUI - Connect
DashboardConnect
GUI - LogsGUI - Peers
LogsPeers
GUI - ForwardsGUI - TUN VPN
ForwardsVPN
GUI - SettingsGUI - Files
SettingsFiles

Android

PeersForwardsFilesVPN
PeersForwardsFilesVPN
Speed TestToolsSettingsLogs
SpeedTestToolsSettingsLogs

Quick Start

1. Deploy Server (One-Click)

curl -fsSL https://raw.githubusercontent.com/uk0/stun_max/main/install.sh | sudo bash

Custom password:

curl -fsSL https://raw.githubusercontent.com/uk0/stun_max/main/install.sh | STUN_MAX_PASSWORD=your_password sudo bash

Custom ports:

curl -fsSL https://raw.githubusercontent.com/uk0/stun_max/main/install.sh | STUN_MAX_PORT=9090 STUN_MAX_STUN_PORT=3479 sudo bash

The script auto-downloads the latest release, configures systemd, and opens firewall ports.

1b. Manual Deploy

./build.sh # Upload to your server scp build/stun_max-server-linux-amd64 root@SERVER:/usr/local/bin/stun_max-server scp build/stun_max-stunserver-linux-amd64 root@SERVER:/usr/local/bin/stun_max-stunserver ssh root@SERVER "mkdir -p /opt/stun_max/web" scp -r build/web/* root@SERVER:/opt/stun_max/web/

Create systemd services:

# Signal Server cat > /etc/systemd/system/stun-max.service << 'EOF' [Unit] Description=STUN Max Signal Server After=network.target [Service] Type=simple ExecStart=/usr/local/bin/stun_max-server --addr :8080 --web-dir /opt/stun_max/web --db /opt/stun_max/stun_max.db --ipdb /opt/stun_max/ip2region.xdb --stun-http http://127.0.0.1:3479 Restart=always RestartSec=3 LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF # STUN Server (optional, recommended for restricted networks) cat > /etc/systemd/system/stun-max-stun.service << 'EOF' [Unit] Description=STUN Max STUN Server After=network.target [Service] Type=simple ExecStart=/usr/local/bin/stun_max-stunserver --addr :3478 --http :3479 Restart=always [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now stun-max stun-max-stun

Get the auto-generated dashboard password:

journalctl -u stun-max | grep Password

Firewall: Open TCP 8080 and UDP 3478.

2. Create a Room

Open http://SERVER:8080, login, create a room with name + password.

3. Connect

GUI (Windows/Mac/Android):

Run stun_max-client-windows-amd64.exe or stun_max-client-darwin-arm64, fill in server URL, room, password, name → Connect.

Android: Install stun_max-android-v*.apk, same UI as desktop with touch-optimized layout.

CLI:

./stun_max-cli --server ws://SERVER:8080/ws --room myroom --password secret --name laptop

4. Port Forwarding

# Forward peer's port to local > forward peer-name 127.0.0.1:3389 > forward peer-name 192.168.1.100:8080 9090 # Manage > forwards # list with traffic stats > unforward 3389 # stop

5. TUN VPN (Subnet Routing)

# Route a remote subnet through peer > vpn peer-name 192.168.1.0/24 > vpn peer-name 192.168.1.0/24 --exit-ip 192.168.1.1 # Check status > vpn status # Stop > vpn stop

6. Speed Test

> speedtest peer-name # default 10MB, auto mode > speedtest peer-name 50 # 50MB test > speedtest peer-name 10 p2p # force P2P transport

7. File Transfer

> send peer-name /path/to/file > transfers # list active transfers

Build

./build.sh # all platforms (server + desktop + CLI) bash android/build-apk.sh v1.0.0 # Android APK go build ./server/ # server only go build ./client/ # GUI client go build -tags cli ./client/ # CLI client go build ./tools/natcheck/ # NAT diagnostic go build ./tools/stunserver/ # STUN server

Android build requires: Android SDK (ANDROID_HOME), NDK, gogio (go install gioui.org/cmd/gogio@latest).

CLI Commands

CommandDescription
peersList peers with P2P/RELAY mode
forward <peer> <host:port> [local]Forward remote port
unforward <port>Stop forward
forwardsList forwards with traffic stats
expose <host:port> <peer> [port]Reverse forward (expose local service)
stunSTUN/P2P connection details
speedtest <peer> [size] [p2p|relay]Bandwidth test
send <peer> <file>Send file to peer
transfersList file transfers
vpn <peer> [subnets...] [--exit-ip IP]Start TUN VPN
vpn statusVPN status with traffic
vpn stopStop VPN
hop <peer-b> <peer-c> <host:port>Multi-hop forward via B to C
helpAll commands
quitDisconnect

Tab completion for commands, peer names, and ports.

GUI Tabs

TabDescription
PeersPeer list with P2P/RELAY badges, STUN endpoints
ForwardsCreate/stop forwards, live traffic (bytes + speed), peer dropdown selector
VPNStart/stop TUN VPN, subnet routing, traffic stats
Speed TestP2P bandwidth test with progress bar and transport display
FilesSend/receive files with progress
SettingsForward control, STUN server selector, autostart, auto-connect
ToolsWindows RDP remote desktop setup
LogsScrollable event log with severity colors

All tabs support vertical scrolling on both desktop and mobile.

Security

FeatureDetail
E2E encryptionX25519 + XChaCha20-Poly1305 for all P2P and relay data
Room isolationRelay verifies sender and receiver in same room
Room authDashboard-only creation, SHA-256 password hash
Rate limitingLogin 5/min, WebSocket 20/min, Join 10/min per IP
Connection limitGlobal max (default 5000, --max-connections)
Session expiryDashboard tokens expire after 24 hours
BlacklistBan/unban clients per room
Forward controlPer-client allow/deny + local-only mode

Server Flags

FlagDefaultDescription
--addr:8080Listen address
--web-password(built-in)Dashboard password
--web-dir../webStatic files path
--dbstun_max.dbSQLite database file
--ipdbip2region.xdbIP geolocation database
--stun-httphttp://127.0.0.1:3479STUN server stats URL
--max-connections5000Max WebSocket connections
--tls-certTLS certificate file
--tls-keyTLS key file

Client Flags (CLI)

FlagDefaultDescription
--serverws://localhost:8080/wsServer URL
--room(required)Room name
--passwordRoom password
--name(hostname)Display name
--stunstun.cloudflare.com:3478STUN servers (comma-separated)
--no-stunfalseRelay only
-vfalseVerbose

Project Structure

server/ Signal + relay + dashboard main.go HTTP/WS, auth, rate limiting, TLS, graceful shutdown hub.go Rooms, peers, blacklist, room ownership client.go Message routing, join validation, same-name kick relay.go Data relay with per-room toggle store.go SQLite persistence (rooms, blacklists) ipinfo.go Offline IP geolocation (ip2region) stats.go Server statistics client/core/ Networking (shared by GUI + CLI) client.go Connection, reconnect, signaling tunnel.go Port forwarding with gVisor transport forward_netstack.go Per-peer gVisor TCP/IP stack for forwards tun.go TUN VPN device, SNAT, MSS clamping tun_netstack.go gVisor TCP/IP stack for VPN subnet proxy tun_proxy.go Legacy ICMP proxy (raw socket) tun_config_*.go Platform-specific TUN setup (darwin/linux/windows) stun.go STUN discovery, hole punch, UDP read loop speedtest.go P2P bandwidth testing crypto.go X25519 + XChaCha20-Poly1305 encryption proxy_bypass.go TUN proxy bypass (physical NIC detection) compress.go Deflate compression with smart bypass udp_reliable.go RUTP reliable UDP (legacy, used by old tunnels) types.go Protocol types events.go Event system client/ui/ Gio UI cross-platform app app.go Window, events, auto-connect connect.go Login screen dashboard.go Tab navigation peers.go Peer list forwards.go Forward management with traffic stats vpn.go TUN VPN control speedtest.go Speed test with P2P mode files.go File transfer tools.go Windows RDP tools peer_selector.go Dropdown peer selector with P2P/RELAY badge settings.go Settings + STUN selector config.go Config persistence logs.go Event log viewer logo.go Embedded app logo platform_android.go Android platform detection platform_other.go Desktop platform detection client/core/ vpn_android.go Android VPN via JNI (VpnService bridge) vpn_stub.go No-op VPN stub for non-Android tun_config_android.go Android TUN device via VpnService fd autohop.go Auto-hop P2P relay discovery android/ Android build pipeline build-apk.sh gogio + dex injection + manifest + signing AndroidManifest.xml VpnService + permissions declaration app/src/main/java/ VpnPermissionActivity, StunMaxVpnService, GoBridge web/ Admin dashboard (HTML/JS/CSS) tools/natcheck/ NAT type diagnostic (RFC 5780, Chinese, proxy bypass) tools/stunserver/ Self-hosted STUN server with HTTP stats tools/punchtest/ Standalone NAT3/NAT4 hole punch test tool

License

AGPL-3.0 — See LICENSE for details.

About

这是一个基于自定义工作流自动创建的临时仓库

285.02 MiB
0 forks0 stars3 branches3 TagREADMEAGPL-3.0 license
Language
Go88%
Shell4.2%
JavaScript3.2%
CSS2.2%
Others2.4%