2023-06-15 06:51:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
using System.Text;
|
2023-06-15 06:51:19 +00:00
|
|
|
|
|
|
|
|
|
namespace NetTunnelApp;
|
|
|
|
|
|
2023-07-25 01:02:16 +00:00
|
|
|
|
public delegate void HeartCallBack(string msg, uint timeStamp);
|
2023-07-14 09:29:02 +00:00
|
|
|
|
|
2023-06-15 06:51:19 +00:00
|
|
|
|
public enum ProtoCryptoType
|
|
|
|
|
{
|
|
|
|
|
CRYPTO_NONE = 0,
|
|
|
|
|
CRYPTO_BASE64 = 1,
|
|
|
|
|
CRYPTO_AES128 = 2,
|
|
|
|
|
CRYPTO_3DES = 3,
|
|
|
|
|
CRYPTO_AES256 = 4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum LogLevel
|
|
|
|
|
{
|
2023-06-19 11:08:42 +00:00
|
|
|
|
LOG_TRACE = 0,
|
|
|
|
|
LOG_DEBUG,
|
|
|
|
|
LOG_INFO,
|
|
|
|
|
LOG_WARN,
|
|
|
|
|
LOG_ERROR,
|
2023-06-20 09:25:14 +00:00
|
|
|
|
LOG_CRITICAL,
|
|
|
|
|
LOG_OFF
|
2023-06-19 11:08:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 01:02:16 +00:00
|
|
|
|
public enum NET_SHARE_MODE
|
|
|
|
|
{
|
|
|
|
|
///< Internet Share Mode(ICS) 模式
|
|
|
|
|
ICS_SHARE_MODE = 0,
|
|
|
|
|
|
|
|
|
|
///< Net Address Translation(NAT) 模式
|
|
|
|
|
NAT_SHARE_MODE = 1
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
|
|
|
public struct VirtualMathineConfig
|
|
|
|
|
{
|
|
|
|
|
///< 用户虚拟机 ID
|
|
|
|
|
public int vmId;
|
|
|
|
|
|
|
|
|
|
///< 用户虚拟机名称
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
|
|
|
|
public string vmName;
|
|
|
|
|
|
|
|
|
|
///< 用户服务端公钥
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string svrPublicKey;
|
|
|
|
|
|
|
|
|
|
///< 用户虚拟机网络地址
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
|
|
|
|
|
public string vmNetwork;
|
|
|
|
|
|
|
|
|
|
///< 用户服务端接入网关
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
|
|
|
|
public string scgGateWay;
|
2023-07-17 10:55:01 +00:00
|
|
|
|
|
|
|
|
|
///< 用户服务端接入网关
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
|
|
|
|
public string scgTunnelGw;
|
2023-07-10 08:36:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
|
|
|
public struct UserClientConfig
|
|
|
|
|
{
|
|
|
|
|
///< 用户接入网关控制 ID
|
|
|
|
|
public int scgCtrlAppId;
|
|
|
|
|
|
|
|
|
|
///< 用户接入网关隧道 ID
|
|
|
|
|
public int scgTunnelAppId;
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
///< 用户客户端私钥
|
2023-07-10 08:36:19 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string cliPrivateKey;
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
///< 用户客户端公钥
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string cliPublicKey;
|
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
///< 用户客户端隧道IP地址
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
|
|
|
|
|
public string cliAddress;
|
|
|
|
|
|
|
|
|
|
///< 用户虚拟机配置列表
|
|
|
|
|
public IntPtr pVMConfig;
|
|
|
|
|
|
|
|
|
|
///< 用户虚拟机配置最大数
|
|
|
|
|
public int tolVM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
|
|
|
public struct FilePath
|
|
|
|
|
{
|
|
|
|
|
public int curUsed;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
|
|
|
|
public string CfgPath;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-19 11:08:42 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
|
|
|
public struct NetCard
|
|
|
|
|
{
|
2023-06-21 10:04:16 +00:00
|
|
|
|
public int IfIndex;
|
|
|
|
|
|
2023-08-21 01:22:52 +00:00
|
|
|
|
public int netConnStatus;
|
|
|
|
|
|
2023-06-20 09:25:14 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
|
2023-06-21 10:04:16 +00:00
|
|
|
|
public string UUID;
|
2023-06-19 11:08:42 +00:00
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string Name;
|
|
|
|
|
|
2023-06-20 09:25:14 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 132)]
|
2023-06-19 11:08:42 +00:00
|
|
|
|
public string Description;
|
|
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
|
2023-06-19 11:08:42 +00:00
|
|
|
|
public string IpAddr;
|
|
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
|
2023-06-19 11:08:42 +00:00
|
|
|
|
public string NetMask;
|
|
|
|
|
|
2023-06-21 10:04:16 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
|
|
|
|
|
public string Gateway;
|
|
|
|
|
|
2023-06-20 09:25:14 +00:00
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
|
2023-06-19 11:08:42 +00:00
|
|
|
|
public string MacAddr;
|
2023-06-15 06:51:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 09:25:14 +00:00
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
|
|
|
public struct WgSvrConfig
|
|
|
|
|
{
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string Name;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
|
|
public string Address;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string PrivateKey;
|
|
|
|
|
|
|
|
|
|
public int ListenPort;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string CliPubKey;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
|
|
|
|
public string AllowNet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
|
|
|
|
public struct WgCliConfig
|
|
|
|
|
{
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string Name;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string PrivateKey;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
|
|
|
|
|
public string Address;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
|
|
|
|
|
public string SvrPubKey;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
|
|
|
|
public string AllowNet;
|
|
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
|
|
|
|
|
public string ServerURL;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 06:51:19 +00:00
|
|
|
|
public class NetTunnelLib
|
|
|
|
|
{
|
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
2023-07-25 01:02:16 +00:00
|
|
|
|
public static extern int TunnelSDKInitEnv(String workDir, String svrUrl, String pLogFile, LogLevel level,
|
|
|
|
|
bool isWorkServer);
|
2023-06-19 11:08:42 +00:00
|
|
|
|
|
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void TunnelSDKUnInit();
|
2023-08-03 09:13:03 +00:00
|
|
|
|
|
2023-06-19 11:08:42 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
2023-07-10 08:36:19 +00:00
|
|
|
|
public static extern int GetAllNICInfo(out IntPtr netCard, ref int size);
|
2023-08-03 09:13:03 +00:00
|
|
|
|
|
2023-07-10 08:36:19 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
2023-07-14 09:29:02 +00:00
|
|
|
|
public static extern int GetUserClientConfigure(String UserName, String token, out IntPtr userCfg);
|
2023-07-10 08:36:19 +00:00
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
2023-07-17 10:55:01 +00:00
|
|
|
|
public static extern int RemoteCtrlSvrCfgUserTunnel(int vmid, String cliNetwork);
|
2023-08-03 09:13:03 +00:00
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int RemoteWireGuardControl(bool startOrStop);
|
|
|
|
|
|
2023-07-17 10:55:01 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int LocalWireGuardControl(bool startOrStop, bool checkPrivate = true);
|
|
|
|
|
|
2023-07-14 09:29:02 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int RemoteHeartControl(bool startOrStop, HeartCallBack cb);
|
|
|
|
|
|
2023-07-25 01:02:16 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern NET_SHARE_MODE GetCurrentNetShareMode();
|
|
|
|
|
|
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern void SetCurrentNetShareMode(NET_SHARE_MODE shareMode);
|
|
|
|
|
|
2023-08-02 08:41:15 +00:00
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern int EnableSCGProxy(bool isEnable, String proxyIp, int proxyPort);
|
|
|
|
|
|
|
|
|
|
[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)]
|
|
|
|
|
public static extern bool UsedSCGProxy();
|
2023-06-15 06:51:19 +00:00
|
|
|
|
}
|