-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Netch.Models; | ||
|
||
namespace Netch.Controllers | ||
{ | ||
public class PcapController : Guard, IModeController | ||
{ | ||
public override string Name { get; } = "pcap2socks"; | ||
|
||
public override string MainFile { get; protected set; } = "pcap2socks.exe"; | ||
|
||
protected override IEnumerable<string> StartedKeywords { get; } = new[] {"└"}; | ||
|
||
private readonly OutboundAdapter _outbound = new(); | ||
|
||
protected override Encoding? InstanceOutputEncoding { get; } = Encoding.UTF8; | ||
|
||
public void Start(in Mode mode) | ||
{ | ||
StartInstanceAuto($@"-i \Device\NPF_{_outbound.NetworkInterface.Id} {mode.FullRule.FirstOrDefault() ?? "-P n"}"); | ||
} | ||
|
||
protected override void OnKeywordStarted() | ||
{ | ||
Thread.Sleep(300); | ||
Utils.Utils.Open(LogPath); | ||
} | ||
|
||
protected override void OnKeywordStopped() | ||
{ | ||
if (File.ReadAllText(LogPath).Length == 0) | ||
{ | ||
Task.Run(() => | ||
{ | ||
Thread.Sleep(1000); | ||
Utils.Utils.Open("https://github.com/zhxie/pcap2socks#dependencies"); | ||
}); | ||
|
||
throw new MessageException("Pleases install pcap2socks's dependency"); | ||
} | ||
|
||
Utils.Utils.Open(LogPath); | ||
} | ||
|
||
public override void Stop() | ||
{ | ||
StopInstance(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule binaries
updated
from 3b545e to f9e9be
Submodule modes
updated
from 13886a to 5f3460