P2P 无中继回退,打洞失败即连接失败,对称 NAT 需对端为 easy 或 hard;对端约半分钟内未互通会退出,需用 -mqtt-wait 与 -mqtt-hello 对齐启动时机;-link 参数值必须加引号,否则解析出错。
gonc
threatexpertMIT活跃维护带自动 NAT 穿透和安全 P2P 的 netcat 增强版,用 Go 编写,支持反弹 shell、文件传输和网络代理,无需公网 IP 即可直连内网机器。
Netcat with automated NAT traversal, secure P2P, and advanced features for shell access, file transfer, and network proxying.
gonc www.baidu.com 80
gonc -p2p <passphrase>README 未说明显存或 GPU 要求,工具为 Golang 编写的网络程序,在普通 CPU 上运行;P2P 穿透依赖公网 STUN 与 MQTT 服务及双方网络 NAT 类型。
带自动 NAT 穿透和安全 P2P 的 netcat,用口令直连两台机器做 shell、传文件和代理
带自动 NAT 穿透和安全 P2P 的 netcat 增强版,用 Go 编写,支持反弹 shell、文件传输和网络代理,无需公网 IP 即可直连内网机器。
核心能力
- 用 -p2p 加共享口令自动发现对端并打洞建连
- 基于口令派生证书,TLS 1.3 端到端加密与双向认证
- 内置 :s5s/:s5c 虚拟命令提供 SOCKS5 代理
- -httpserver 与 -download 支持断点续传的目录传输
- -exec 可为每条连接启动服务,如 :sh 反向 shell
容易踩的坑
- v2.6.12最新正式版2026-11-07 · 2026-11-07 03:26 UTC
Full Changelog: https://github.com/threatexpert/gonc/compare/v2.6.11...v2.6.12
- v2.6.112026-10-26 · 2026-10-26 03:14 UTC
查看更新说明
Full Changelog: https://github.com/threatexpert/gonc/compare/v2.6.10...v2.6.11
- 修复
-W -k长时间待机时每隔 30 分钟报告P2P failed的问题。启用 keep-open 后持续等待连接;不带-k时仍保留 30 分钟等待超时。自动启用 keep-open 的模式同样适用。 - MQTT 待机期间保持同一会话,自动重连并保留故障状态,避免重复输出同一故障告警;订阅恢复后记录恢复信息。
- 修复
-x2备用代理连接、认证或 UDP 转发准备失败时阻断 P2P 的问题。现在会提示原因并继续尝试直连;-x保持原有失败行为。 - 将
-x2代理准备的超时参数从 20 秒调整为 15 秒,并在连接前显示初始化提示、代理地址和超时参数。-x仍为 20 秒。 - 修正 SOCKS5 UDP ASSOCIATE 请求,使用
0.0.0.0:0作为未指定地址,提高代理兼容性。 - 导出
apps.ServeTunnelConn接口,支持在独立 TCP/TLS 连接或 mux stream 上处理单个 TCP/UDP 隧道代理会话。 - 更新 Win7 构建脚本中的兼容 Go 工具链下载链接至
1.26.8-1。
English
- Fixed recurring
P2P failedmessages every 30 minutes during idle-W -koperation. Keep-open listeners now wait continuously; listeners without-kretain the 30-minute timeout. Modes that enable keep-open automatically receive the same behavior. - Preserved the MQTT session and failure tracking throughout idle waiting, allowing automatic reconnection without repeated alerts for the same outage. Recovery is logged when subscriptions become available again.
- Fixed
-x2fallback relay connection, authentication, or UDP setup failures preventing P2P attempts. These failures now produce a warning and allow direct P2P to proceed. Required proxy behavior with-xremains unchanged. - Reduced the
-x2proxy setup timeout setting from 20 to 15 seconds. Added an initialization message showing the proxy address and timeout before connecting. The-xtimeout remains 20 seconds. - Corrected SOCKS5 UDP ASSOCIATE requests to use
0.0.0.0:0as the unspecified address, improving proxy compatibility. - Exported
apps.ServeTunnelConnto handle a single TCP/UDP tunnel proxy session over a dedicated TCP/TLS connection or mux stream. - Updated the Win7 build script’s compatible Go toolchain download link to
1.26.8-1.
- 修复
- v2.6.102026-09-28 · 2026-09-28 03:00 UTC
查看更新说明
Full Changelog: https://github.com/threatexpert/gonc/compare/v2.6.9...v2.6.10
中文
- 安全隧道: 为 Link 隧道增加 socks5 Over TLS-PSK ;启用 -k 后,隧道断开可自动重连。
- MQTT 信令: 增加订阅重试和连接诊断,将首次连接等待限制为 15 秒,并为后台发布设置时限。
- UDP 打洞: 改进接收端口保留和失败诊断,提高连接建立的可靠性。
- 文件下载: 加强路径校验,防止文件写入下载目录之外。
- 构建与依赖: 升级至 Go 1.26.8,并更新关键依赖。 English
- Secure tunnels: Added TLS-PSK authentication for Link tunnels and automatic reconnection with -k.
- MQTT signaling: Added subscription retries and clearer diagnostics, limited the initial connection wait to 15 seconds, and bounded background publishing.
- UDP hole punching: Improved receiver retention and failure diagnostics for more reliable connection setup.
- File downloads: Strengthened path validation to prevent writes outside the download directory.
- Build and dependencies: Upgraded to Go 1.26.8 and refreshed key dependencies.
- v2.6.92026-07-28 · 2026-07-28 04:03 UTC
查看更新说明
Full Changelog: https://github.com/threatexpert/gonc/compare/v2.6.8...v2.6.9
- v2.6.82026-07-23 · 2026-07-23 23:23 UTC
查看更新说明
Full Changelog: https://github.com/threatexpert/gonc/compare/v2.6.7...v2.6.8
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Introduction to gonc
gonc is a Golang-based netcat tool designed to facilitate peer-to-peer communication. Its main features include:
-
🔁 Automated NAT Traversal: Zero configuration. Both sides only need to agree on a passphrase. By using the -p2p parameter, peers can automatically discover each other’s network addresses and establish a point-to-point connection through NAT traversal, leveraging public STUN and MQTT services for address exchange.
-
🔒 End-to-End Encrypted with Mutual Authentication: Supports TLS for TCP and DTLS for UDP encrypted transmission, with passphrase-based mutual identity authentication.
-
🧩 Flexible Service Configuration: With the -e parameter, you can flexibly set the application to serve each connection. For example, -e /bin/sh can provide a remote cmd shell. You can also use built-in virtual commands for convenient SOCKS5 service, HTTP file service, and traffic forwarding.
Related Projects
- gonc-gui — a desktop (Windows) and Android app built on
gonc: convenient cross-device, cross-network P2P direct connection and secure file transfer. Just share a passphrase (or scan a QR code); no command line required.
Usage Examples
Basic Usage
-
Use it like
nc:gonc www.baidu.com 80 gonc -tls www.baidu.com 443can only establish point-to-point connections based on IP and port.
-
Now, you can also establish point-to-point connections based on a shared passphrase, with automated NAT traversal.
The following diagram shows the process of gonc establishing a P2P connection between a home broadband network (hard NAT) and a peer on a mobile network (symmetric NAT). Since both sides have IPv6, the -4 option is used on both ends to force IPv4 in order to demonstrate NAT traversal.

P2P Tunnel and HTTP File Server
-
Both sides agree on the same passphrase. On the sender side, start an HTTP file server to expose the files or directories to be shared. The -httpserver option accepts multiple paths, each of which can be either a single file or a directory:
gonc -p2p <passphrase> -httpserver c:/RootDir1 c:/RootDir2 -
On the receiving side, there are two options:
-
Automatically download the entire directory
After running the following command, all files will be downloaded recursively to the local machine. If the process is interrupted, re-running the command will automatically resume from where it left off:
gonc -p2p <passphrase> -download c:/SavePath -
Browse and selectively download via browser
This option does not start downloading automatically. Instead, you need to manually open a browser and visit http://127.0.0.1:9999 to view the peer’s file list and download files as needed:
gonc -p2p <passphrase> -httplocal-port 9999If you need to download a specific subdirectory, the browser becomes inconvenient, but you can do it like this:
gonc -http-download c:/SavePath http://127.0.0.1:9999/subdir
Secure Encrypted P2P Communication
-
Establish secure encrypted P2P communication between two different networks by agreeing on a passphrase (use
gonc -psk .to generate a high-entropy passphrase to replacepassphrase). This passphrase is used for mutual discovery and certificate derivation, ensuring communication security with TLS 1.3.gonc -p2p passphraseOn the other side, use the same parameters (the program will automatically attempt TCP or UDP communication (TCP preferred), negotiate roles (TLS client/server), and complete the TLS protocol):
gonc -p2p passphraseNote that if the other end delays the running time, it will exit if it cannot find the other end to interact with information within about half a minute. Therefore, it also supports a waiting mechanism based on MQTT message subscription, using -mqtt-wait and -mqtt-hello to synchronize the timing of the two parties to start P2P. For example, the following uses -mqtt-wait to wait continuously,
gonc -p2p passphrase -mqtt-waitOn the other side,
gonc -p2p passphrase -mqtt-hello -
Check your NAT type
gonc -nat-checkerThis will check your IPv6 and IPv4 TCP and UDP NAT addresses and analyze port changes after NAT. If no TCP6 or UDP6 addresses are listed, it means you don't have IPv6. Each protocol address ends with "(easy)", indicating the highest success rate for hole punching; "(hard)" indicates a higher success rate; and "(symm)" is the most difficult. Symm requires the other end to be either "easy" or "hard" for P2P to work.
Reverse Shell (Pseudo-Terminal Support for UNIX-like Systems)
- Listener (does not use
-keep-open, accepts only one connection; no authentication with-psk):gonc -tls -exec ":sh /bin/bash" -l 1234 - Connect to obtain a shell (supports TAB, Ctrl+C, etc.):
gonc -tls -pty x.x.x.x 1234 - Use P2P for reverse shell (
passphraseis used for authentication, ensuring secure communication with TLS 1.3):
On the other side:gonc -exec ":sh /bin/bash" -p2p passphrasegonc -pty -p2p passphrase
Transmission Speed Test
- Send data and measure transmission speed (built-in
/dev/zeroand/dev/urandom):
Example output:gonc.exe -send /dev/zero -P x.x.x.x 1234
On the receiving side:IN: 76.8 MiB (80543744 bytes), 3.3 MiB/s | OUT: 0.0 B (0 bytes), 0.0 B/s | 00:00:23gonc -P -l 1234 > NUL
P2P Tunnel and SOCKS5 / HTTP Proxy
-
Wait for the tunnel to be established:
gonc -p2p passphrase -linkagent -
On the other side, start a local SOCKS5 / HTTP proxy service on port 3080 to access the remote network:
# The link option controls how the local and remote proxy endpoints are created. # Use none to indicate that no listening port is opened on that side: gonc -p2p passphrase -link "3080;none"Next, for example, if you want to connect to 10.0.0.1:3389 in the remote network, you can simply enter the following address in your local Remote Desktop client:
10.0.0.1-3389.gonc.cc:3080This domain will be resolved into an IP in the form of 127.b.c.d. As a result, the Remote Desktop client will connect to the local SOCKS5 proxy on port 3080, and then gonc will reverse-parse the 127.b.c.d address to extract the information 10.0.0.1-3389 from the domain name.
-
link Configuration Format
# Based on the established tunnel, both local and remote sides listen on port 1080. # The proxy supports both HTTP and SOCKS5 protocols, with transparent proxy capability enabled. gonc -p2p <passphrase> -link "1080;1080" # Below is the configuration method for the URL format. The parameter value of -link must be enclosed in quotes; otherwise, parsing problems may occur. # The left side x://0.0.0.0:1080?tproxy=1 is equivalent to simply writing 1080. # The right side enables port 1080 on the remote host, without transparent proxy support. gonc -p2p <passphrase> -link "x://0.0.0.0:1080?tproxy=1;x://127.0.0.1:1080" # The left side f://127.0.0.1:1080?to=1.2.3.4:80 # means listening locally on port 1080 and forwarding traffic to 1.2.3.4:80 on the remote side. # The right side 'none' indicates that no port is opened remotely. gonc -p2p <passphrase> -link "f://127.0.0.1:1080?to=1.2.3.4:80;none" # The right side f://0.0.0.0:80?to=127.0.0.1:80 # means listening on port 80 on the remote side and forwarding traffic back to 127.0.0.1:80 locally. gonc -p2p <passphrase> -link "none;f://0.0.0.0:80?to=127.0.0.1:80" # The left side x+tls means the proxy protocol with TLS encryption and allows for certificate configuration. The right side specifies the outbound IP address via `outbound_bind` (suitable for multi-IP environments). gonc -p2p <口令> -link "x+tls://user:[email protected]:1080?cert=ca.pem&key=key.pem;none?outbound_bind=10.0.0.5"
Flexible Service Configuration
- Use
-execto flexibly configure the application to provide services for each connection. For example, instead of specifying/bin/bashfor shell commands, it can also be used for port forwarding. However, the following example starts a newgoncprocess for each connection:gonc -keep-open -exec "gonc -tls www.baidu.com 443" -l 8000 - To avoid spawning multiple child processes, use the built-in nc module:
gonc -keep-open -exec ":nc -tls www.baidu.com 443" -l 8000
Socks5 Proxy Service
-
Configure client mode:
gonc -x s.s.s.s:port x.x.x.x 1234 -
Built-in Socks5 server: Use
-e :s5sto provide standard Socks5 service. Support-authto set a username and password for Socks5. Use-keep-opento continuously accept client connections to the Socks5 server. Thanks to Golang's goroutines, it achieves good multi-client concurrency performance:gonc -e ":s5s -auth user:passwd" -keep-open -l 1080 -
Secure Socks5 over TLS: Since standard Socks5 is unencrypted, use
-e :s5swith-tlsand-pskto customize secure Socks5 over TLS communication. Use-Pto monitor connection transmission information, and-aclto implement access control for incoming connections and proxy destinations. For theacl.txtfile format, see acl-example.txt.gonc.exe -tls -psk passphrase -e :s5s -keep-open -acl acl.txt -P -l 1080On the other side, use
:s5c(built-in s5c command) to convert Socks5 over TLS to standard Socks5, providing local client access on 127.0.0.1:3080:gonc.exe -e ":s5c -tls -psk passphrase x.x.x.x 1080" -keep-open -l -local 127.0.0.1:3080
Establishing a Tunnel for Other Applications
-
Assist WireGuard in NAT Traversal to Form a VPN
On the passive (listening) side, PC-S, run the following command (using the WireGuard peer’s public key as the passphrase, and assuming WireGuard is listening on port 51820):
gonc -p2p <PublicKey-of-PS-S> -mqtt-wait -u -k -e ":nc -u 127.0.0.1 51820"On the active (initiating) side, PC-C, set the WireGuard peer (PS-S)'s Endpoint to 127.0.0.1:51821, with its own WireGuard interface listening on 51820. Then run the following command. The -k flag allows gonc to automatically reconnect if the network drops:
gonc -p2p <PublicKey-of-PS-S> -mqtt-hello -u -k -e ":nc -u -local 127.0.0.1:51821 127.0.0.1 51820"
P2P NAT Traversal Capabilities
How does gonc establish a P2P connection?
- Concurrently uses multiple public STUN servers to detect local TCP/UDP NAT mappings and intelligently determine NAT type
- Exchanges address information securely via public MQTT servers, using a hash derived from the SessionKey as the shared topic
- Attempts direct connection in the following priority order: IPv6 TCP > IPv4 TCP > IPv4 UDP, aiming for true peer-to-peer communication
- No relay servers are used, and no fallback mechanisms are provided — either the connection fails, or it's a real P2P success
How to Deploy a Relay Server for Cases Where P2P Is Not Feasible
-
A SOCKS5 server with UDP ASSOCIATE support running on a public IP is sufficient as a relay. You can also run gonc's built-in SOCKS5 proxy on your own VPS to act as a relay server.
The following command starts a SOCKS5 proxy that only supports UDP forwarding. The -psk and -tls options enable encryption and PSK-based authentication. Note: Don’t just open port 1080 in your firewall—UDP forwarding uses random ports for each session.
gonc -e ":s5s -u -c=0" -psk <password> -tls -k -l 1080 -
When P2P fails, you only need one side of gonc to retry the P2P process using the -x option to route through the SOCKS5 relay:
gonc -p2p <passphrase> -x "-psk <password> -tls <socks5server-ip>:1080"Alternatively, you can use a standard SOCKS5 proxy server that supports UDP forwarding:
gonc -p2p <passphrase> -x "<socks5server-ip>:1080" -auth "user:password"
For example, if both peers are behind symmetric NATs and P2P fails, having just one side use a SOCKS5 UDP relay effectively changes its NAT behavior to “easy,” making it much easier to establish a connection. The data remains end-to-end encrypted.
Used public servers(STUN & MQTT):
"tcp://turn.cloudflare.com:80",
"udp://turn.cloudflare.com:53",
"udp://stun.l.google.com:19302",
"stun.gonc.cc:3478",
"global.turn.twilio.com:3478",
"stun.nextcloud.com:443",
"tcp://broker.hivemq.com:1883",
"tcp://broker.emqx.io:1883",
"tcp://test.mosquitto.org:1883",
"tcp://mqtt.gonc.cc:1883"
How effective is gonc at NAT traversal?
Except in symmetric NAT scenarios on both ends, gonc achieves a very high success rate
gonc classifies NAT types into three categories:
-
Easy: A single internal port maps to the same external port across multiple STUN servers
-
Hard: A single internal port maps to a consistent but different external port across STUN servers — harder than type 1
-
Symmetric: A single internal port maps to different external ports depending on the destination — the most difficult type
To handle these NAT types, gonc employs several traversal strategies:
-
Uses multiple STUN servers to detect NAT behavior and identify multi-exit IP scenarios
-
Prefers IPv6 connections when both sides support it (e.g., TCP6-to-TCP6 direct dial)
-
Both peers listen on TCP while simultaneously dialing each other to increase TCP hole punching success
-
The peer with the easier NAT delays its initial UDP packet to avoid triggering port changes on the harder side
-
The peer with the harder NAT sends UDP packets with a low TTL to reduce interference from the remote firewall
-
As a last resort, uses a "birthday paradox" strategy: the harder side uses 600 random source ports, and the other side tries 600 random destination ports, increasing the chance of a successful UDP port collision