示例#1
0
 public TunAdapter()
 {
     InterfaceIndex   = RouteHelper.ConvertLuidToIndex(tun2socks.tun_luid());
     NetworkInterface = NetworkInterfaceUtils.Get((int)InterfaceIndex);
     Gateway          = IPAddress.Parse(Global.Settings.TUNTAP.Gateway);
     Global.Logger.Info($"WinTUN 适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {InterfaceIndex}");
 }
示例#2
0
        public OutboundAdapter()
        {
            // 寻找出口适配器
            if (IpHlpApi.GetBestRoute(BitConverter.ToUInt32(IPAddress.Parse("114.114.114.114").GetAddressBytes(), 0), 0, out var pRoute) != 0)
            {
                throw new MessageException("GetBestRoute 搜索失败");
            }

            NetworkInterface = NetworkInterfaceUtils.Get((int)pRoute.dwForwardIfIndex);

            Address        = new IPAddress(pRoute.dwForwardNextHop.S_addr);
            InterfaceIndex = pRoute.dwForwardIfIndex;
            Gateway        = new IPAddress(pRoute.dwForwardNextHop.S_un_b);

            Global.Logger.Info($"出口 网关 地址:{Gateway}");
            Global.Logger.Info($"出口适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {InterfaceIndex}");
        }