https://github.com/josexy/netstackgo
An easy-to-use netstack, wrapped by gvisor and wireguard-go, which supports macOS/Linux/Windows.
https://github.com/josexy/netstackgo
golang gvisor netstack tun
Last synced: 2 months ago
JSON representation
An easy-to-use netstack, wrapped by gvisor and wireguard-go, which supports macOS/Linux/Windows.
- Host: GitHub
- URL: https://github.com/josexy/netstackgo
- Owner: josexy
- License: gpl-3.0
- Created: 2023-03-26T12:00:15.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-24T11:52:51.000Z (over 1 year ago)
- Last Synced: 2025-06-07T06:37:26.217Z (4 months ago)
- Topics: golang, gvisor, netstack, tun
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# netstackgo
> ⚠️ **Deprecated: This project is no longer maintained.**
>
> Please use https://github.com/josexy/cropstun instead.An easy-to-use netstack, wrapped by gvisor and wireguard-go, which supports macOS/Linux/Windows.
```shell
go get github.com/josexy/netstackgo
```# usage
```go
type myHandler struct{}func (*myHandler) HandleTCPConn(info *netstackgo.ConnTuple, conn net.Conn) {
log.Printf("tcp, src: %s, dst: %s", info.Src(), info.Dst())
// do something...
}
func (*myHandler) HandleUDPConn(info *netstackgo.ConnTuple, conn net.PacketConn) {
log.Printf("udp, src: %s, dst: %s", info.Src(), info.Dst())
// do something...
}func main() {
nt := netstackgo.New(tun.TunConfig{
Name: "tun2",
Addr: "192.18.0.1/16",
MTU: tun.DefaultMTU,
})
if err := nt.Start(); err != nil {
log.Fatal(err)
}
defer nt.Close()
nt.RegisterConnHandler(&myHandler{})
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGINT)
<-interrupt
}
```PS: Windows user requires downloading wintun.dll from https://www.wintun.net
# credits
- [clash](https://github.com/Dreamacro/clash)
- [tun2socks](https://github.com/xjasonlyu/tun2socks)
- [gvisor](https://github.com/google/gvisor)
- [wireguard-go](https://git.zx2c4.com/wireguard-go)