2023-06-15 06:51:19 +00:00
|
|
|
|
using System;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
using System.Buffers;
|
2023-06-15 06:51:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2023-06-15 06:51:19 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
|
2023-06-15 06:51:19 +00:00
|
|
|
|
|
2023-06-19 11:08:42 +00:00
|
|
|
|
namespace NetTunnelApp;
|
|
|
|
|
|
|
|
|
|
public partial class MainForm : Form
|
2023-06-15 06:51:19 +00:00
|
|
|
|
{
|
2023-06-19 11:08:42 +00:00
|
|
|
|
public MainForm()
|
2023-06-15 06:51:19 +00:00
|
|
|
|
{
|
2023-06-19 11:08:42 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
var path = Environment.CurrentDirectory + "\\tunnelsdk_" +
|
|
|
|
|
string.Format("{0:yyyyMMdd}", DateTime.Now) + ".log";
|
|
|
|
|
NetTunnelLib.InitTunnelSDKLog(path, LogLevel.LOG_DEBUG);
|
|
|
|
|
|
|
|
|
|
NetTunnelLib.TunnelSDKInitEnv(Environment.CurrentDirectory);
|
|
|
|
|
}
|
2023-06-15 06:51:19 +00:00
|
|
|
|
|
2023-06-20 09:25:14 +00:00
|
|
|
|
private void test_get_network_info()
|
2023-06-19 11:08:42 +00:00
|
|
|
|
{
|
|
|
|
|
IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NetCard)) * 32);
|
|
|
|
|
int size = 0;
|
|
|
|
|
|
2023-06-20 09:25:14 +00:00
|
|
|
|
var v = NetTunnelLib.GetAllNICInfo(pt, ref size);
|
2023-06-19 11:08:42 +00:00
|
|
|
|
|
|
|
|
|
Console.WriteLine("Result {0}, total {1}", v, size);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
|
{
|
|
|
|
|
IntPtr ptr = new IntPtr(pt.ToInt64() + Marshal.SizeOf(typeof(NetCard)) * i);
|
|
|
|
|
NetCard card = (NetCard)Marshal.PtrToStructure(ptr, typeof(NetCard));
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Name:{0}", card.Name);
|
|
|
|
|
Console.WriteLine("Description:{0}", card.Description);
|
|
|
|
|
Console.WriteLine("Ip:{0}", card.IpAddr);
|
|
|
|
|
Console.WriteLine("NetMask:{0}", card.NetMask);
|
|
|
|
|
Console.WriteLine("MacAddr:{0}", card.MacAddr);
|
2023-06-15 06:51:19 +00:00
|
|
|
|
}
|
2023-06-19 11:08:42 +00:00
|
|
|
|
|
|
|
|
|
Marshal.FreeHGlobal(pt);
|
2023-06-15 06:51:19 +00:00
|
|
|
|
}
|
2023-06-20 09:25:14 +00:00
|
|
|
|
|
|
|
|
|
private void test_create_wg_key()
|
|
|
|
|
{
|
|
|
|
|
var buffer = new StringBuilder(64 + 1);
|
|
|
|
|
var buffer2 = new StringBuilder(64 + 1);
|
|
|
|
|
var v = NetTunnelLib.GenerateWireguardKeyPairs(buffer, 64, buffer2, 64);
|
|
|
|
|
lstLogs.Items.Add(v.ToString() + ": [" + buffer.ToString() + "] / [" + buffer2.ToString() + "]");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void test_create_wg_svr_cfg()
|
|
|
|
|
{
|
|
|
|
|
WgSvrConfig wsg = new WgSvrConfig();
|
|
|
|
|
|
|
|
|
|
wsg.Name = "wg_svr";
|
|
|
|
|
wsg.Address = "10.10.10.250/24";
|
|
|
|
|
wsg.ListenPort = 10000;
|
|
|
|
|
wsg.PrivateKey = "EOHYEXSK4xw0LlB4I3ZlF5UqSaoma3Ea2KPhLfIdA14=";
|
|
|
|
|
wsg.CliPubKey = "6BWnmkCJqJC5iNoCEZWTxwGNG7qwkxFoVgAk4DoIKCk=";
|
|
|
|
|
wsg.AllowNet = "10.10.10.5/32";
|
|
|
|
|
|
|
|
|
|
var v = NetTunnelLib.WireGuardCreateServerConfig(wsg);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Create WireGuard Server Configure File: {0}", v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void test_create_wg_cli_cfg()
|
|
|
|
|
{
|
|
|
|
|
WgCliConfig cli = new WgCliConfig();
|
|
|
|
|
|
|
|
|
|
cli.Name = "wg_cli";
|
|
|
|
|
cli.Address = "10.10.10.1/32";
|
|
|
|
|
cli.PrivateKey = "WGAlqvys3O83VmWug6Z8NzUrxGr/PNHSeOVFnKLSe2k=";
|
|
|
|
|
|
|
|
|
|
cli.SvrPubKey = "8KEaqtWM5U35SR8S3QJriGHPr0VIqvk8A7BEuOjjp1M=";
|
|
|
|
|
cli.AllowNet = "10.10.10.0/24, 10.0.4.16/30";
|
|
|
|
|
cli.ServerURL = "101.35.234.160:10010";
|
|
|
|
|
|
|
|
|
|
var v = NetTunnelLib.WireGuardCreateClientConfig(cli);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Create WireGuard Client Configure File: {0}", v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var buffer = new StringBuilder(256 + 1);
|
|
|
|
|
//NetTunnelLib.TunnelSDKInitEnv();
|
|
|
|
|
var v = NetTunnelLib.FindWireguardExe(buffer, 256);
|
|
|
|
|
MessageBox.Show(buffer.ToString() + "----" + v.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
test_create_wg_svr_cfg();
|
|
|
|
|
test_create_wg_cli_cfg();
|
|
|
|
|
}
|
2023-06-19 11:08:42 +00:00
|
|
|
|
}
|