Compare commits
13 Commits
33a795c813
...
main
Author | SHA1 | Date | |
---|---|---|---|
eb09a42dc6
|
|||
1a4ad9a18f
|
|||
38ce3b2071
|
|||
23995df656
|
|||
bde7c4fe6f
|
|||
7924aea2c3
|
|||
ae52121509
|
|||
d990b6aaca
|
|||
5ac2571680
|
|||
68812721a1
|
|||
6409416961
|
|||
b8d17ddb96
|
|||
1a8469c264
|
@@ -13,7 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" Version="0.49.2-preview.0.71" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.49.2-preview.0.71"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -1,9 +1,226 @@
|
||||
namespace PortProxyTool.Cli;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace PortProxyTool.Cli;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
if (args.Length == 0)
|
||||
AnsiConsole.MarkupLine(
|
||||
$"[red]用法[/][gray]: [/][white]{Environment.ProcessPath ?? Environment.GetCommandLineArgs()[0]} [red]<命令>[/] [gray][[<参数>]][/][/]");
|
||||
else
|
||||
switch (args[0])
|
||||
{
|
||||
case "add":
|
||||
switch (args.Length)
|
||||
{
|
||||
case 6:
|
||||
var targetType = PortProxyUtil.GetPortProxyTypeByString(args[1]);
|
||||
if (targetType == null)
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的第一个参数为 v4tov4, v4tov6, v6tov6, v6tov4[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ushort.TryParse(args[3], out var listenPort))
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的第三个参数为 0 - 65535[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ushort.TryParse(args[5], out var targetPort))
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的第五个参数为 0 - 65535[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
var item = new PortProxyItem
|
||||
{
|
||||
Type = (PortProxyType)targetType,
|
||||
ListenAddress = args[2],
|
||||
ListenPort = listenPort,
|
||||
TargetAddress = args[4],
|
||||
TargetPort = targetPort
|
||||
};
|
||||
var result = PortProxy.Add(item);
|
||||
AnsiConsole.MarkupLine(string.IsNullOrEmpty(result)
|
||||
? "[green]添加成功[/]"
|
||||
: $"[red]添加失败[/][gray]:[/] [white]{result}[/]");
|
||||
break;
|
||||
default:
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的参数为 <v4tov4/v4tov6/v6tov6/v6tov4> <监听地址> <监听端口> <目标地址> <目标端口>[/]");
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
case "remove":
|
||||
switch (args.Length)
|
||||
{
|
||||
case 4:
|
||||
var targetType = PortProxyUtil.GetPortProxyTypeByString(args[1]);
|
||||
var result = PortProxy.Remove(targetType, args[2], args[3]);
|
||||
AnsiConsole.MarkupLine(string.IsNullOrEmpty(result)
|
||||
? "[green]删除成功[/]"
|
||||
: $"[red]删除失败[/][gray]:[/] [white]{result}[/]");
|
||||
break;
|
||||
default:
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的参数为 <v4tov4/v4tov6/v6tov6/v6tov4> <监听地址> <监听端口>[/]");
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
case "set":
|
||||
switch (args.Length)
|
||||
{
|
||||
case 6:
|
||||
var targetType = PortProxyUtil.GetPortProxyTypeByString(args[1]);
|
||||
if (targetType == null)
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的第一个参数为 v4tov4, v4tov6, v6tov6, v6tov4[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ushort.TryParse(args[3], out var listenPort))
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的第三个参数为 0 - 65535[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ushort.TryParse(args[5], out var targetPort))
|
||||
{
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的第五个参数为 0 - 65535[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
var item = new PortProxyItem
|
||||
{
|
||||
Type = (PortProxyType)targetType,
|
||||
ListenAddress = args[2],
|
||||
ListenPort = listenPort,
|
||||
TargetAddress = args[4],
|
||||
TargetPort = targetPort
|
||||
};
|
||||
var result = PortProxy.Set(item);
|
||||
AnsiConsole.MarkupLine(string.IsNullOrEmpty(result)
|
||||
? "[green]设置成功[/]"
|
||||
: $"[red]设置失败[/][gray]:[/] [white]{result}[/]");
|
||||
break;
|
||||
default:
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的参数为 <v4tov4/v4tov6/v6tov6/v6tov4> <监听地址> <监听端口> <目标地址> <目标端口>[/]");
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
case "list":
|
||||
switch (args.Length)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
var portProxies = PortProxy.GetPortProxies();
|
||||
if (portProxies.Length == 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]无端口代理[/]");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.MarkupLine("[white]端口代理列表[/][gray]: [/]");
|
||||
for (var index = 0; index < portProxies.Length; index++)
|
||||
{
|
||||
var portProxy = portProxies[index];
|
||||
var type = portProxy.Type switch
|
||||
{
|
||||
PortProxyType.V4ToV4 => "[green]IPv4[/] [white]->[/] [green]IPv4[/]",
|
||||
PortProxyType.V4ToV6 => "[green]IPv4[/] [white]->[/] [blue]IPv6[/]",
|
||||
PortProxyType.V6ToV6 => "[blue]IPv6[/] [white]->[/] [blue]IPv6[/]",
|
||||
PortProxyType.V6ToV4 => "[blue]IPv6[/] [white]->[/] [green]IPv4[/]",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
var targetPort = portProxy.TargetPort switch
|
||||
{
|
||||
null => "[red]未知[/]",
|
||||
_ => portProxy.TargetPort.ToString()
|
||||
};
|
||||
AnsiConsole.MarkupLine(
|
||||
$"[gray]{index + 1}.[/] {type} [gray]|[/] [white]{portProxy.ListenAddress}[/][gray]:[/][white]{portProxy.ListenPort}[/][gray] -> [/][white]{portProxy.TargetAddress ?? "[red]未知[/]"}[/][gray]:[/][white]{targetPort}[/]");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
PortProxyType type;
|
||||
switch (args[1])
|
||||
{
|
||||
case "v4tov4":
|
||||
type = PortProxyType.V4ToV4;
|
||||
break;
|
||||
case "v4tov6":
|
||||
type = PortProxyType.V4ToV6;
|
||||
break;
|
||||
case "v6tov6":
|
||||
type = PortProxyType.V6ToV6;
|
||||
break;
|
||||
case "v6tov4":
|
||||
type = PortProxyType.V6ToV4;
|
||||
break;
|
||||
default:
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]参数错误[/][gray]:[/] [white]接受的参数为 v4tov4, v4tov6, v6tov6, v6tov4[/]");
|
||||
return;
|
||||
}
|
||||
|
||||
var portProxies = PortProxy.GetPortProxies().Where(x => x.Type == type).ToArray();
|
||||
if (portProxies.Length == 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]无端口代理[/]");
|
||||
}
|
||||
else
|
||||
{
|
||||
var typeStr = type switch
|
||||
{
|
||||
PortProxyType.V4ToV4 => "[green]IPv4[/] [white]->[/] [green]IPv4[/]",
|
||||
PortProxyType.V4ToV6 => "[green]IPv4[/] [white]->[/] [blue]IPv6[/]",
|
||||
PortProxyType.V6ToV6 => "[blue]IPv6[/] [white]->[/] [blue]IPv6[/]",
|
||||
PortProxyType.V6ToV4 => "[blue]IPv6[/] [white]->[/] [green]IPv4[/]",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
AnsiConsole.MarkupLine($"[white]{typeStr} 端口代理列表[/][gray]: [/]");
|
||||
for (var index = 0; index < portProxies.Length; index++)
|
||||
{
|
||||
var portProxy = portProxies[index];
|
||||
var targetPort = portProxy.TargetPort switch
|
||||
{
|
||||
null => "[red]未知[/]",
|
||||
_ => portProxy.TargetPort.ToString()
|
||||
};
|
||||
AnsiConsole.MarkupLine(
|
||||
$"[gray]{index + 1}.[/] {typeStr} [gray]|[/] [white]{portProxy.ListenAddress}[/][gray]:[/][white]{portProxy.ListenPort}[/][gray] -> [/][white]{portProxy.TargetAddress ?? "[red]未知[/]"}[/][gray]:[/][white]{targetPort}[/]");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AnsiConsole.MarkupLine(
|
||||
"[red]用法错误[/][gray]:[/] [white]get [gray][[v4tov4/v4tov6/v6tov6/v6tov4]][/][/]");
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
default:
|
||||
AnsiConsole.MarkupLine("[red]命令没有找到[/][gray]:[/] [white]接受的命令为 add, remove, set, list[/]");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
<Application x:Class="PortProxyTool.Wpf.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
StartupUri="/Views/MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
|
@@ -0,0 +1,17 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace PortProxyTool.Wpf.Converters;
|
||||
|
||||
public class NullableUnknownToStringConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
return value == null ? "未知" : value.ToString();
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@@ -1,9 +0,0 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d"
|
||||
Title="PortProxyTool" Height="450" Width="800">
|
||||
<Grid />
|
||||
</Window>
|
@@ -1,14 +0,0 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
@@ -13,4 +13,13 @@
|
||||
<ProjectReference Include="..\PortProxyTool\PortProxyTool.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="Views\MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<XamlRuntime>Wpf</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
14
PortProxyTool.Wpf/Rules/PortValidationRule.cs
Normal file
14
PortProxyTool.Wpf/Rules/PortValidationRule.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PortProxyTool.Wpf.Rules;
|
||||
|
||||
public class PortValidationRule : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object? value, CultureInfo cultureInfo)
|
||||
{
|
||||
if (value is not string strValue) return new ValidationResult(false, "请输入有效的数字");
|
||||
if (string.IsNullOrEmpty(strValue) || ushort.TryParse(strValue, out _)) return ValidationResult.ValidResult;
|
||||
return new ValidationResult(false, "请输入有效的数字");
|
||||
}
|
||||
}
|
200
PortProxyTool.Wpf/Views/MainWindow.xaml
Normal file
200
PortProxyTool.Wpf/Views/MainWindow.xaml
Normal file
@@ -0,0 +1,200 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.Views.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:converters="clr-namespace:PortProxyTool.Wpf.Converters"
|
||||
mc:Ignorable="d"
|
||||
Title="PortProxyTool GUI" Height="450" Width="800"
|
||||
MinHeight="450" MinWidth="800">
|
||||
<Window.Resources>
|
||||
<converters:NullableUnknownToStringConverter x:Key="NullableUnknownToStringConverter" />
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0">
|
||||
<Button MinHeight="24"
|
||||
Click="RefreshButton_OnClick">
|
||||
刷新
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<Grid Grid.Row="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv4 -> IPv4"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V4ToV4ListBox"
|
||||
SelectionChanged="V4ToV4ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V4ToV4RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V4ToV4SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv4 -> IPv6"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V4ToV6ListBox"
|
||||
SelectionChanged="V4ToV6ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V4ToV6RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V4ToV6SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Column="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv6 -> IPv6"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V6ToV6ListBox"
|
||||
SelectionChanged="V6ToV6ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V6ToV6RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V6ToV6SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
<Grid Grid.Column="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0"
|
||||
Text="IPv6 -> IPv4"
|
||||
HorizontalAlignment="Center" />
|
||||
<ListBox Grid.Row="1"
|
||||
Name="V6ToV4ListBox"
|
||||
SelectionChanged="V6ToV4ListBox_OnSelectionChanged">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{Binding ListenAddress}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock Text="{Binding ListenPort}" />
|
||||
<TextBlock Text=" -> " />
|
||||
<TextBlock
|
||||
Text="{Binding TargetAddress, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
<TextBlock Text=":" />
|
||||
<TextBlock
|
||||
Text="{Binding TargetPort, Converter={StaticResource NullableUnknownToStringConverter}}" />
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button Grid.Row="2"
|
||||
Name="V6ToV4RemoveButton"
|
||||
Click="RemoveButton_OnClick">
|
||||
删除
|
||||
</Button>
|
||||
<Button Grid.Row="3"
|
||||
Name="V6ToV4SetButton"
|
||||
Click="SetButton_OnClick">
|
||||
编辑
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<StackPanel Grid.Row="2">
|
||||
<Button MinHeight="24"
|
||||
Click="AddButton_OnClick">
|
||||
添加
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
202
PortProxyTool.Wpf/Views/MainWindow.xaml.cs
Normal file
202
PortProxyTool.Wpf/Views/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using PortProxyTool.Wpf.Views.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private List<PortProxyItem> _portProxies = [];
|
||||
public PortProxyItem? V4ToV4SelectedItem;
|
||||
public PortProxyItem? V4ToV6SelectedItem;
|
||||
public PortProxyItem? V6ToV4SelectedItem;
|
||||
public PortProxyItem? V6ToV6SelectedItem;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void RefreshButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button) return;
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void RefreshListBox()
|
||||
{
|
||||
_portProxies = PortProxy.GetPortProxies().ToList();
|
||||
V4ToV4ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V4ToV4);
|
||||
V4ToV6ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V4ToV6);
|
||||
V6ToV6ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V6ToV6);
|
||||
V6ToV4ListBox.ItemsSource = _portProxies.Where(x => x.Type == PortProxyType.V6ToV4);
|
||||
}
|
||||
|
||||
private void V4ToV4ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V4ToV4SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void V4ToV6ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V4ToV6SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void V6ToV6ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V6ToV6SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void V6ToV4ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (sender is ListBox listBox)
|
||||
V6ToV4SelectedItem = listBox.SelectedItem as PortProxyItem;
|
||||
}
|
||||
|
||||
private void AddButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button) return;
|
||||
AddWindow addWindow = new();
|
||||
addWindow.ShowDialog();
|
||||
if (addWindow.DialogResult == true)
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button) return;
|
||||
switch (button.Name)
|
||||
{
|
||||
case "V4ToV4RemoveButton":
|
||||
if (V4ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V4ToV4SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
case "V4ToV6RemoveButton":
|
||||
if (V4ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V4ToV6SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV6RemoveButton":
|
||||
if (V6ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V6ToV6SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV4RemoveButton":
|
||||
if (V6ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要删除的条目", "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = PortProxy.Remove(V6ToV4SelectedItem);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
MessageBox.Show("删除成功", "删除成功", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
else
|
||||
MessageBox.Show(result, "删除失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
private void SetButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is not Button button) return;
|
||||
SetWindow setWindow;
|
||||
switch (button.Name)
|
||||
{
|
||||
case "V4ToV4SetButton":
|
||||
if (V4ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V4ToV4SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
case "V4ToV6SetButton":
|
||||
if (V4ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V4ToV6SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV6SetButton":
|
||||
if (V6ToV6SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V6ToV6SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
case "V6ToV4SetButton":
|
||||
if (V6ToV4SelectedItem is null)
|
||||
{
|
||||
MessageBox.Show("请选择要编辑的条目", "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindow = new SetWindow(V6ToV4SelectedItem);
|
||||
setWindow.ShowDialog();
|
||||
RefreshListBox();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
83
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml
Normal file
83
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml
Normal file
@@ -0,0 +1,83 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.Views.Windows.AddWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:rules="clr-namespace:PortProxyTool.Wpf.Rules"
|
||||
mc:Ignorable="d"
|
||||
Title="添加 PortProxy" Height="450" Width="800"
|
||||
MinWidth="400" MinHeight="280">
|
||||
<Grid Margin="16">
|
||||
<StackPanel>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">类型</Label>
|
||||
<ComboBox Grid.Column="1"
|
||||
x:Name="TypeComboBox"
|
||||
SelectedIndex="{Binding TypeIndex}">
|
||||
<ComboBoxItem>IPv4 -> IPv4</ComboBoxItem>
|
||||
<ComboBoxItem>IPv4 -> IPv6</ComboBoxItem>
|
||||
<ComboBoxItem>IPv6 -> IPv6</ComboBoxItem>
|
||||
<ComboBoxItem>IPv6 -> IPv4</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding ListenAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="ListenPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding TargetAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="TargetPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Button Margin="4"
|
||||
Content="添加"
|
||||
MinHeight="24"
|
||||
Click="AddButton_OnClick" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
48
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml.cs
Normal file
48
PortProxyTool.Wpf/Views/Windows/AddWindow.xaml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf.Views.Windows;
|
||||
|
||||
public partial class AddWindow : Window
|
||||
{
|
||||
public AddWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public int TypeIndex { get; set; } = 0;
|
||||
public string ListenAddress { get; set; } = "0.0.0.0";
|
||||
public ushort ListenPort { get; set; } = 12345;
|
||||
public string TargetAddress { get; set; } = "127.0.0.1";
|
||||
public ushort TargetPort { get; set; } = 12345;
|
||||
|
||||
private void AddButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var type = TypeIndex switch
|
||||
{
|
||||
0 => PortProxyType.V4ToV4,
|
||||
1 => PortProxyType.V4ToV6,
|
||||
2 => PortProxyType.V6ToV6,
|
||||
3 => PortProxyType.V6ToV4,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
var item = new PortProxyItem
|
||||
{
|
||||
Type = type,
|
||||
ListenAddress = ListenAddress,
|
||||
ListenPort = ListenPort,
|
||||
TargetAddress = TargetAddress,
|
||||
TargetPort = TargetPort
|
||||
};
|
||||
var result = PortProxy.Add(item);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
DialogResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogResult = false;
|
||||
MessageBox.Show(result, "添加失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
70
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml
Normal file
70
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml
Normal file
@@ -0,0 +1,70 @@
|
||||
<Window x:Class="PortProxyTool.Wpf.Views.Windows.SetWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:rules="clr-namespace:PortProxyTool.Wpf.Rules"
|
||||
mc:Ignorable="d"
|
||||
Title="编辑 PortProxy" Height="450" Width="800"
|
||||
MinWidth="400" MinHeight="280">
|
||||
<Grid Margin="16">
|
||||
<StackPanel>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding Item.ListenAddress}"
|
||||
IsEnabled="False" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">监听端口</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
IsEnabled="False">
|
||||
<TextBox.Text>
|
||||
<Binding Path="Item.ListenPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接地址</Label>
|
||||
<TextBox Grid.Column="1"
|
||||
Text="{Binding TargetAddress}" />
|
||||
</Grid>
|
||||
<Grid Margin="4">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label Grid.Column="0">目标连接端口</Label>
|
||||
<TextBox Grid.Column="1">
|
||||
<TextBox.Text>
|
||||
<Binding Path="TargetPort" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<rules:PortValidationRule />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<Button Margin="4"
|
||||
Content="编辑"
|
||||
MinHeight="24"
|
||||
Click="SetButton_OnClick" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
35
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml.cs
Normal file
35
PortProxyTool.Wpf/Views/Windows/SetWindow.xaml.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace PortProxyTool.Wpf.Views.Windows;
|
||||
|
||||
public partial class SetWindow : Window
|
||||
{
|
||||
public SetWindow(PortProxyItem item)
|
||||
{
|
||||
Item = item;
|
||||
TargetAddress = item.TargetAddress ?? "127.0.0.1";
|
||||
TargetPort = item.TargetPort ?? 12345;
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
public PortProxyItem Item { get; set; }
|
||||
public string TargetAddress { get; set; }
|
||||
public ushort TargetPort { get; set; }
|
||||
|
||||
private void SetButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Item.TargetAddress = TargetAddress;
|
||||
Item.TargetPort = TargetPort;
|
||||
var result = PortProxy.Set(Item);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
DialogResult = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogResult = false;
|
||||
MessageBox.Show(result, "编辑失败", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,4 +3,5 @@
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANumber_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe3157c720a4245958cf8a1b12c4b4a27e90928_003Fd9_003F56dcb09d_003FNumber_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANumber_002EParsing_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fde8a243f75215d958afa80cf80a41b4981a44efea7db93bffcdaf7bd6ba378c0_003FNumber_002EParsing_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelpers_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fe3157c720a4245958cf8a1b12c4b4a27e90928_003Fbb_003Fec9f78bc_003FThrowHelpers_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc7102cd0ffb8973777e61b1942c3fffac7e14016a511d055c3adf73ff91748_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AThrowHelper_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Fc7102cd0ffb8973777e61b1942c3fffac7e14016a511d055c3adf73ff91748_003FThrowHelper_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AXamlReader_002Ecs_002Fl_003AC_0021_003FUsers_003FJack_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F9f3f6ac2973b52b9b246bc900a441bf6a7cc21b73be1a5faf7f363865e61_003FXamlReader_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
@@ -78,7 +78,7 @@ public static class PortProxy
|
||||
{
|
||||
var output =
|
||||
ExecuteCommand(
|
||||
$"delete {type.ToString().ToLower()} listenaddress=\"{listenAddress}\" listenport=\"{listenPort}\" connectAddress=\"{connectAddress}\" connectPort=\"{connectPort}\" protocol=\"{protocol}\"");
|
||||
$"add {type.ToString().ToLower()} listenaddress=\"{listenAddress}\" listenport=\"{listenPort}\" connectAddress=\"{connectAddress}\" connectPort=\"{connectPort}\" protocol=\"{protocol}\"");
|
||||
return output.Length > 0 ? output[0] : string.Empty;
|
||||
}
|
||||
|
||||
|
16
PortProxyTool/PortProxyUtil.cs
Normal file
16
PortProxyTool/PortProxyUtil.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace PortProxyTool;
|
||||
|
||||
public static class PortProxyUtil
|
||||
{
|
||||
public static PortProxyType? GetPortProxyTypeByString(string type)
|
||||
{
|
||||
return type.ToLower() switch
|
||||
{
|
||||
"v4tov4" => PortProxyType.V4ToV4,
|
||||
"v4tov6" => PortProxyType.V4ToV6,
|
||||
"v6tov6" => PortProxyType.V6ToV6,
|
||||
"v6tov4" => PortProxyType.V6ToV4,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user