Skip to content

Commit

Permalink
Add commandline options for listen directly to local or any interfaces.
Browse files Browse the repository at this point in the history
Fix GH-83
  • Loading branch information
haga-rak committed May 5, 2023
1 parent e819a6b commit 0edfc37
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/Fluxzy.Cli/Commands/StartCommandBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public Command Build(CancellationToken cancellationToken)
var command = new Command("start", "Start a capturing session");

command.AddOption(CreateListenInterfaceOption());
command.AddOption(CreateListenLocalhost());
command.AddOption(CreateListToAllInterfaces());
command.AddOption(CreateOutputFileOption());
command.AddOption(CreateDumpToFolderOption());
command.AddOption(CreateSystemProxyOption());
Expand All @@ -82,6 +84,8 @@ public async Task Run(InvocationContext invocationContext, CancellationToken pro
var proxyStartUpSetting = FluxzySetting.CreateDefault();

var listenInterfaces = invocationContext.Value<List<IPEndPoint>>("listen-interface");
var listenLocalHost = invocationContext.Value<bool>("llo");
var listenAnyInterfaces = invocationContext.Value<bool>("lany");
var outFileInfo = invocationContext.Value<FileInfo>("output-file");
var dumpDirectory = invocationContext.Value<DirectoryInfo>("dump-folder");
var registerAsSystemProxy = invocationContext.Value<bool>("system-proxy");
Expand Down Expand Up @@ -110,7 +114,22 @@ public async Task Run(InvocationContext invocationContext, CancellationToken pro

proxyStartUpSetting.ClearBoundAddresses();

foreach (var item in listenInterfaces) {

var finalListenInterfaces = listenInterfaces.ToList();

if (listenLocalHost) {
finalListenInterfaces.Clear();
finalListenInterfaces.Add(new IPEndPoint(IPAddress.Loopback, 44344));
finalListenInterfaces.Add(new IPEndPoint(IPAddress.IPv6Loopback, 44344));
}

if (listenAnyInterfaces) {
finalListenInterfaces.Clear();
finalListenInterfaces.Add(new IPEndPoint(IPAddress.Any, 44344));
finalListenInterfaces.Add(new IPEndPoint(IPAddress.IPv6Any, 44344));
}

foreach (var item in finalListenInterfaces) {
proxyStartUpSetting.AddBoundAddress(item);
}

Expand Down Expand Up @@ -347,6 +366,30 @@ private static Option CreateSkipSslOption()
return option;
}

private static Option CreateListenLocalhost()
{
var option = new Option<bool>(
"--llo",
"Listen on localhost address with default port. Same as -l 127.0.0.1/44344");

option.SetDefaultValue(false);
option.Arity = ArgumentArity.Zero;

return option;
}

private static Option CreateListToAllInterfaces()
{
var option = new Option<bool>(
"--lany",
"Listen on all interfaces with default port (44344)");

option.SetDefaultValue(false);
option.Arity = ArgumentArity.Zero;

return option;
}

private static Option CreateBouncyCastleOption()
{
var option = new Option<bool>(
Expand Down

0 comments on commit 0edfc37

Please sign in to comment.