2021-10-12 19:46:53 +02:00
|
|
|
//go:build ignore
|
2021-11-05 01:52:54 +01:00
|
|
|
// +build ignore
|
2021-01-21 00:02:32 +01:00
|
|
|
|
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
2022-09-20 17:21:32 +02:00
|
|
|
* Copyright (C) 2017-2022 WireGuard LLC. All Rights Reserved.
|
2021-01-21 00:02:32 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2022-03-17 00:09:48 +01:00
|
|
|
"net/netip"
|
2021-01-21 00:02:32 +01:00
|
|
|
|
2021-03-06 16:21:18 +01:00
|
|
|
"golang.zx2c4.com/wireguard/conn"
|
2021-01-21 00:02:32 +01:00
|
|
|
"golang.zx2c4.com/wireguard/device"
|
|
|
|
"golang.zx2c4.com/wireguard/tun/netstack"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
tun, tnet, err := netstack.CreateNetTUN(
|
2021-11-05 01:52:54 +01:00
|
|
|
[]netip.Addr{netip.MustParseAddr("192.168.4.29")},
|
|
|
|
[]netip.Addr{netip.MustParseAddr("8.8.8.8")},
|
2021-01-21 00:02:32 +01:00
|
|
|
1420)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
2021-03-06 16:21:18 +01:00
|
|
|
dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, ""))
|
2021-01-21 00:02:32 +01:00
|
|
|
dev.IpcSet(`private_key=a8dac1d8a70a751f0f699fb14ba1cff7b79cf4fbd8f09f44c6e6a90d0369604f
|
|
|
|
public_key=25123c5dcd3328ff645e4f2a3fce0d754400d3887a0cb7c56f0267e20fbf3c5b
|
|
|
|
endpoint=163.172.161.0:12912
|
|
|
|
allowed_ip=0.0.0.0/0
|
|
|
|
`)
|
2021-02-10 00:12:23 +01:00
|
|
|
err = dev.Up()
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
2021-01-21 00:02:32 +01:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|