mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2025-04-26 19:03:43 +02:00
There are more places where we'll need to add it later, when Go 1.18 comes out with support for it in the "net" package. Also, allowedips still uses slices internally, which might be suboptimal. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
//go:build ignore
|
|
// +build ignore
|
|
|
|
/* SPDX-License-Identifier: MIT
|
|
*
|
|
* Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
|
|
"golang.zx2c4.com/go118/netip"
|
|
"golang.zx2c4.com/wireguard/conn"
|
|
"golang.zx2c4.com/wireguard/device"
|
|
"golang.zx2c4.com/wireguard/tun/netstack"
|
|
)
|
|
|
|
func main() {
|
|
tun, tnet, err := netstack.CreateNetTUN(
|
|
[]netip.Addr{netip.MustParseAddr("192.168.4.29")},
|
|
[]netip.Addr{netip.MustParseAddr("8.8.8.8")},
|
|
1420)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, ""))
|
|
dev.IpcSet(`private_key=a8dac1d8a70a751f0f699fb14ba1cff7b79cf4fbd8f09f44c6e6a90d0369604f
|
|
public_key=25123c5dcd3328ff645e4f2a3fce0d754400d3887a0cb7c56f0267e20fbf3c5b
|
|
endpoint=163.172.161.0:12912
|
|
allowed_ip=0.0.0.0/0
|
|
`)
|
|
err = dev.Up()
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
|
|
client := http.Client{
|
|
Transport: &http.Transport{
|
|
DialContext: tnet.DialContext,
|
|
},
|
|
}
|
|
resp, err := client.Get("https://www.zx2c4.com/ip")
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
log.Panic(err)
|
|
}
|
|
log.Println(string(body))
|
|
}
|