云盘
志元云盘
备份云盘
Home
/
志元云盘
/
webdav
/
sync
/
go
/
peerguard
/
vpn
File
OriginalPic
Thumbnails
CopyAllDownloadUrl
EditTime
Size
iface
2024-09-26 16:51:09
4.3 KB
packet.go
2024-09-26 17:46:46
396 B
README.md
2024-09-26 16:51:09
1.09 KB
vpn.go
2024-09-26 17:47:09
5.38 KB
# VPN a Virtual Private Network library ### Example **peer1** ```go packetConn, err := net.ListenPacket("udp", "192.168.3.99:22334") if err != nil { panic(err) } iface, err := iface.Create("tun1", iface.Config{MTU: 1428, IPv4: "10.10.10.2/24"}) if err != nil { panic(err) } iface.AddPeer("10.10.10.1", "", &net.UDPAddr{IP: net.ParseIP("192.168.3.98", Port: 22335)}) ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer cancel() err := vpn.New(vpn.Config{MTU: 1428}).Run(ctx, iface, packetConn) if err != nil { panic(err) } ``` **peer2** ```go packetConn, err := net.ListenPacket("udp", "192.168.3.98:22335") if err != nil { panic(err) } iface, err := iface.Create("tun1", iface.Config{MTU: 1428, IPv4: "10.10.10.1/24"}) if err != nil { panic(err) } iface.AddPeer("10.10.10.2", "", &net.UDPAddr{IP: net.ParseIP("192.168.3.99", Port: 22334)}) ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer cancel() err := vpn.New(vpn.Config{MTU: 1428}).Run(ctx, iface, packetConn) if err != nil { panic(err) } ```
2025-08-29 16:36:35 Friday 216.73.216.167 Runningtime:0.057s Mem:1.47 MB