mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
27 lines
863 B
C#
27 lines
863 B
C#
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.NetworkInformation;
|
|
using Netch.Interops;
|
|
using Netch.Utils;
|
|
|
|
namespace Netch.Models
|
|
{
|
|
public class TunAdapter : IAdapter
|
|
{
|
|
public TunAdapter()
|
|
{
|
|
InterfaceIndex = (int) NativeMethods.ConvertLuidToIndex(TUNInterop.tun_luid());
|
|
NetworkInterface = NetworkInterface.GetAllNetworkInterfaces().First(i => i.GetIPProperties().GetIPv4Properties().Index == InterfaceIndex);
|
|
Gateway = IPAddress.Parse(Global.Settings.TUNTAP.Gateway);
|
|
|
|
Global.Logger.Info($"WinTUN 适配器:{NetworkInterface.Name} {NetworkInterface.Id} {NetworkInterface.Description}, index: {InterfaceIndex}");
|
|
}
|
|
|
|
|
|
public int InterfaceIndex { get; }
|
|
|
|
public IPAddress Gateway { get; }
|
|
|
|
public NetworkInterface NetworkInterface { get; }
|
|
}
|
|
} |