static void Main(string[] args) { NdisApiDotNet ndisapi = new NdisApiDotNet(null); Console.ResetColor(); Console.CancelKeyPress += HandleCancelKeyPress; if (!ndisapi.IsDriverLoaded()) { Console.WriteLine("WinpkFilter driver is not loaded. Exiting."); return; } var vpnAdapter = NetworkAdapterHelper.GetVpnAdapter(ndisapi); var normalAdapter = NetworkAdapterHelper.GetNormalAdapter(ndisapi); var tableList = IpHelperWrapper.GetTcpConnections("firefox"); foreach (var line in tableList) { Console.WriteLine($"Source: {line.Local.Address} Port: {line.Local.Port} -> Destination: {line.Remote.Address} Port: {line.Remote.Port}"); } Console.ReadLine(); LoadOutFilter(vpnAdapter.Handle, tableList); LoadInFilter(normalAdapter.Handle, tableList); LoadFilterEverythingElseFilter(vpnAdapter.Handle); LoadFilterEverythingElseFilter(normalAdapter.Handle); var loaded = ndisapi.SetPacketFilterTable(filterList); outWorker.DoWork += (s, e) => { TreatOUTPacketsVPNtoNormal(ndisapi, vpnAdapter, normalAdapter); }; inWorker.DoWork += (s, e) => { TreatINPacketsNormaltoVPN(ndisapi, normalAdapter, vpnAdapter); }; Console.WriteLine("-- Filtering started"); outWorker.RunWorkerAsync(); inWorker.RunWorkerAsync(); Console.ReadLine(); Console.WriteLine("-- Filtering stopped"); DumpStaticFilters(ndisapi); Console.WriteLine("Stopped!"); Console.ReadLine(); }
static void Main(string[] args) { NdisApiDotNet ndisapi = new NdisApiDotNet(null); Console.ResetColor(); Console.CancelKeyPress += HandleCancelKeyPress; if (!ndisapi.IsDriverLoaded()) { Console.WriteLine("WinpkFilter driver is not loaded. Exiting."); return; } var vpnAdapter = NetworkAdapterHelper.GetAdapterById(ndisapi, vpnAdapterID); vpnIP = NetworkAdapterHelper.GetAdapterLocalIP(vpnAdapterID); vpnMacAddress = NetworkAdapterHelper.GetAdapterPhisicalAddress(vpnAdapterID); var normalAdapter = NetworkAdapterHelper.GetAdapterById(ndisapi, normalAdapterID); localIp = NetworkAdapterHelper.GetAdapterLocalIP(normalAdapterID); localMacAddress = NetworkAdapterHelper.GetAdapterPhisicalAddress(normalAdapterID); Console.WriteLine($"======================================================================================"); Console.WriteLine($"Found Ethernet Adapter MAC: {localMacAddress} IP: {localIp}"); Console.WriteLine($"Found VPN Adapter MAC: {vpnMacAddress} IP: {vpnIP}"); Console.WriteLine($"======================================================================================"); if (vpnIP == null) { throw new Exception("VPN not connected"); } var tableList = IpHelperWrapper.GetTcpConnections("firefox"); Console.WriteLine(); Console.WriteLine($"==============================FireFox sockets========================================="); Console.WriteLine($"======================================================================================"); foreach (var line in tableList) { Console.WriteLine($"Source: {line.Local.Address} Port: {line.Local.Port} -> Destination: {line.Remote.Address} Port: {line.Remote.Port}"); } Console.WriteLine($"======================================================================================"); Console.ReadLine(); LoadOutFilter(vpnAdapter.Handle, tableList); LoadInFilter(normalAdapter.Handle, tableList); //LoadTESTInFilter(normalAdapter.Handle, tableList); //LoadTESTOutFilter(normalAdapter.Handle, tableList); //LoadTESTInFilter(vpnAdapter.Handle, tableList); LoadFilterEverythingElseFilter(vpnAdapter.Handle); LoadFilterEverythingElseFilter(normalAdapter.Handle); var loaded = ndisapi.SetPacketFilterTable(filterList); outWorker.DoWork += (s, e) => { TreatOUTPacketsVPNtoNormal(ndisapi, vpnAdapter, normalAdapter); }; inWorker.DoWork += (s, e) => { TreatINPacketsNormaltoVPN(ndisapi, normalAdapter, vpnAdapter); }; Console.WriteLine("-- Filtering started"); outWorker.RunWorkerAsync(); inWorker.RunWorkerAsync(); Console.ReadLine(); Console.WriteLine("-- Filtering stopped"); DumpStaticFilters(ndisapi); Console.WriteLine("Stopped!"); Console.ReadLine(); }