Skip to content

An easy-to-use netstack, wrapped by gvisor and wireguard-go, which supports macOS/Linux/Windows.

License

Notifications You must be signed in to change notification settings

josexy/netstackgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

go get github.com/josexy/netstackgo

usage

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

About

An easy-to-use netstack, wrapped by gvisor and wireguard-go, which supports macOS/Linux/Windows.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published