using System; using System.Buffers; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; namespace NetTunnelApp; public partial class MainForm : Form { public MainForm() { InitializeComponent(); var path = Environment.CurrentDirectory + "\\tunnelsdk_" + string.Format("{0:yyyyMMdd}", DateTime.Now) + ".log"; NetTunnelLib.InitTunnelSDKLog(path, LogLevel.LOG_DEBUG); NetTunnelLib.TunnelSDKInitEnv(Environment.CurrentDirectory); } 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) { var buffer = new StringBuilder(64 + 1); var buffer2 = new StringBuilder(64 + 1); //var v = NetTunnelLib.RunPipeCmd("cmd.exe /C dir E:\\", buffer, 4096); //MessageBox.Show(buffer.ToString() + "\nResult: " + v.ToString()); var v = NetTunnelLib.GenerateWireguardKeyPairs(buffer, 64, buffer2, 64); lstLogs.Items.Add(v.ToString() + ": [" + buffer.ToString() + "] / [" + buffer2.ToString() + "]"); IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NetCard)) * 32); int size = 0; v = NetTunnelLib.GetAllNICInfo(pt, ref size); 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); } Marshal.FreeHGlobal(pt); } }