using System.Runtime.InteropServices; namespace Netch { public static class NativeMethods { /// /// 创建路由规则 /// /// 目标地址 /// CIDR /// 网关地址 /// 适配器索引 /// 跃点数 /// 是否成功 [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl, EntryPoint = "CreateRoute")] public static extern bool CreateRoute(string address, int cidr, string gateway, int index, int metric = 0); /// /// 删除路由规则 /// /// 目标地址 /// 掩码地址 /// 网关地址 /// 适配器索引 /// 跃点数 /// 是否成功 [DllImport("RouteHelper.bin", CallingConvention = CallingConvention.Cdecl, EntryPoint = "DeleteRoute")] public static extern bool DeleteRoute(string address, int cidr, string gateway, int index, int metric = 0); [DllImport("dnsapi", EntryPoint = "DnsFlushResolverCache")] public static extern uint FlushDNSResolverCache(); [DllImport("kernel32.dll")] public static extern bool AllocConsole(); [DllImport("kernel32.dll")] public static extern bool AttachConsole(int dwProcessId); } }