This commit is contained in:
zmjack 2020-11-23 00:45:06 +08:00
parent 194c10d1cc
commit bf44a2bc87
10 changed files with 65 additions and 93 deletions

View File

@ -102,7 +102,8 @@
resources.GetString("comboBox_type.Items"),
resources.GetString("comboBox_type.Items1"),
resources.GetString("comboBox_type.Items2"),
resources.GetString("comboBox_type.Items3")});
resources.GetString("comboBox_type.Items3"),
resources.GetString("comboBox_type.Items4")});
this.comboBox_type.Name = "comboBox_type";
//
// NewProxy

View File

@ -9,12 +9,13 @@ namespace PortProxyGUI
public partial class NewProxy : Form
{
public readonly PortProxyGUI PortProxyGUI;
private string AutoString { get; }
public NewProxy(PortProxyGUI portProxyGUI)
{
PortProxyGUI = portProxyGUI;
InitializeComponent();
AutoString = comboBox_type.Text = comboBox_type.Items.OfType<string>().First();
}
private void AddPortProxy(string type, string listenOn, string listenPort, string connectTo, string connectPort)
@ -25,13 +26,18 @@ namespace PortProxyGUI
private bool IsIPv4(string ip)
{
if (ip == "localhost" || ip == "*") return true;
else return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
}
private bool IsIPv6(string ip)
{
if (ip == "localhost" || ip == "*") return true;
else return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
}
private string GetPassType(string listenOn, string connectTo)
{
var from = IsIPv6(listenOn) ? "v6" : "v4";
var to = IsIPv6(connectTo) ? "v6" : "v4";
return $"{from}to{to}";
}
private void button1_Click(object sender, EventArgs e)
@ -54,37 +60,11 @@ namespace PortProxyGUI
return;
}
if (string.IsNullOrEmpty(type))
if (type == AutoString) type = GetPassType(listenOn, connectTo);
if (!new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
{
if (IsIPv4(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v4tov4";
else if (IsIPv4(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v4tov6";
else if (IsIPv6(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v6tov4";
else if (IsIPv6(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v6tov6";
else
{
MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else if (new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
{
bool invalid = false;
switch (type)
{
case "v4tov4": if (!IsIPv4(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
case "v4tov6": if (!IsIPv4(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
case "v6tov4": if (!IsIPv6(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
case "v6tov6": if (!IsIPv6(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
}
if (invalid)
{
MessageBox.Show($"The type ({type}) is invalid for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else
{
MessageBox.Show($"Unknow type ({type}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
MessageBox.Show($"Unknow type for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
@ -93,7 +73,6 @@ namespace PortProxyGUI
private void NewProxy_Load(object sender, EventArgs e)
{
}
private void NewProxy_FormClosing(object sender, FormClosingEventArgs e)

View File

@ -394,15 +394,18 @@
<value>Popup</value>
</data>
<data name="comboBox_type.Items" xml:space="preserve">
<value>v4tov4</value>
<value>(Auto)</value>
</data>
<data name="comboBox_type.Items1" xml:space="preserve">
<value>v4tov6</value>
<value>v4tov4</value>
</data>
<data name="comboBox_type.Items2" xml:space="preserve">
<value>v6tov4</value>
<value>v4tov6</value>
</data>
<data name="comboBox_type.Items3" xml:space="preserve">
<value>v6tov4</value>
</data>
<data name="comboBox_type.Items4" xml:space="preserve">
<value>v6tov6</value>
</data>
<data name="comboBox_type.Location" type="System.Drawing.Point, System.Drawing">

View File

@ -258,16 +258,16 @@
<data name="&gt;&gt;textBox_listenPort.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="comboBox_type.Items" xml:space="preserve">
<data name="comboBox_type.Items1" xml:space="preserve">
<value>v4tov4</value>
</data>
<data name="comboBox_type.Items1" xml:space="preserve">
<data name="comboBox_type.Items2" xml:space="preserve">
<value>v4tov6</value>
</data>
<data name="comboBox_type.Items2" xml:space="preserve">
<data name="comboBox_type.Items3" xml:space="preserve">
<value>v6tov4</value>
</data>
<data name="comboBox_type.Items3" xml:space="preserve">
<data name="comboBox_type.Items4" xml:space="preserve">
<value>v6tov6</value>
</data>
<data name="&gt;&gt;comboBox_type.Name" xml:space="preserve">
@ -453,4 +453,7 @@
<data name="textBox_listenPort.TextAlign" type="System.Windows.Forms.HorizontalAlignment, System.Windows.Forms">
<value>Center</value>
</data>
<data name="comboBox_type.Items" xml:space="preserve">
<value>(自动)</value>
</data>
</root>

View File

@ -7,9 +7,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("PortProxyGUI - NET")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("nstandard.net")]
[assembly: AssemblyProduct("PortProxyGUI - NET")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright © nstandard.net 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]

View File

@ -102,7 +102,8 @@
resources.GetString("comboBox_type.Items"),
resources.GetString("comboBox_type.Items1"),
resources.GetString("comboBox_type.Items2"),
resources.GetString("comboBox_type.Items3")});
resources.GetString("comboBox_type.Items3"),
resources.GetString("comboBox_type.Items4")});
this.comboBox_type.Name = "comboBox_type";
//
// NewProxy

View File

@ -9,12 +9,13 @@ namespace PortProxyGUI
public partial class NewProxy : Form
{
public readonly PortProxyGUI PortProxyGUI;
private string AutoString { get; }
public NewProxy(PortProxyGUI portProxyGUI)
{
PortProxyGUI = portProxyGUI;
InitializeComponent();
AutoString = comboBox_type.Text = comboBox_type.Items.OfType<string>().First();
}
private void AddPortProxy(string type, string listenOn, string listenPort, string connectTo, string connectPort)
@ -25,13 +26,18 @@ namespace PortProxyGUI
private bool IsIPv4(string ip)
{
if (ip == "localhost" || ip == "*") return true;
else return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
return ip.IsMatch(new Regex(@"^(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])){3}$"));
}
private bool IsIPv6(string ip)
{
if (ip == "localhost" || ip == "*") return true;
else return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
return ip.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
}
private string GetPassType(string listenOn, string connectTo)
{
var from = IsIPv6(listenOn) ? "v6" : "v4";
var to = IsIPv6(connectTo) ? "v6" : "v4";
return $"{from}to{to}";
}
private void button1_Click(object sender, EventArgs e)
@ -54,37 +60,11 @@ namespace PortProxyGUI
return;
}
if (string.IsNullOrEmpty(type))
if (type == AutoString) type = GetPassType(listenOn, connectTo);
if (!new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
{
if (IsIPv4(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v4tov4";
else if (IsIPv4(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v4tov6";
else if (IsIPv6(listenOn) && IsIPv4(connectTo)) type = comboBox_type.Text = "v6tov4";
else if (IsIPv6(listenOn) && IsIPv6(connectTo)) type = comboBox_type.Text = "v6tov6";
else
{
MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else if (new[] { "v4tov4", "v4tov6", "v6tov4", "v6tov6" }.Contains(type))
{
bool invalid = false;
switch (type)
{
case "v4tov4": if (!IsIPv4(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
case "v4tov6": if (!IsIPv4(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
case "v6tov4": if (!IsIPv6(listenOn) || !IsIPv4(connectTo)) invalid = true; break;
case "v6tov6": if (!IsIPv6(listenOn) || !IsIPv6(connectTo)) invalid = true; break;
}
if (invalid)
{
MessageBox.Show($"The type ({type}) is invalid for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else
{
MessageBox.Show($"Unknow type ({type}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
MessageBox.Show($"Unknow type for ({listenOn} -> {connectTo}).", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
@ -93,7 +73,6 @@ namespace PortProxyGUI
private void NewProxy_Load(object sender, EventArgs e)
{
}
private void NewProxy_FormClosing(object sender, FormClosingEventArgs e)

View File

@ -394,15 +394,18 @@
<value>Popup</value>
</data>
<data name="comboBox_type.Items" xml:space="preserve">
<value>v4tov4</value>
<value>(Auto)</value>
</data>
<data name="comboBox_type.Items1" xml:space="preserve">
<value>v4tov6</value>
<value>v4tov4</value>
</data>
<data name="comboBox_type.Items2" xml:space="preserve">
<value>v6tov4</value>
<value>v4tov6</value>
</data>
<data name="comboBox_type.Items3" xml:space="preserve">
<value>v6tov4</value>
</data>
<data name="comboBox_type.Items4" xml:space="preserve">
<value>v6tov6</value>
</data>
<data name="comboBox_type.Location" type="System.Drawing.Point, System.Drawing">

View File

@ -258,16 +258,16 @@
<data name="&gt;&gt;textBox_listenPort.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="comboBox_type.Items" xml:space="preserve">
<data name="comboBox_type.Items1" xml:space="preserve">
<value>v4tov4</value>
</data>
<data name="comboBox_type.Items1" xml:space="preserve">
<data name="comboBox_type.Items2" xml:space="preserve">
<value>v4tov6</value>
</data>
<data name="comboBox_type.Items2" xml:space="preserve">
<data name="comboBox_type.Items3" xml:space="preserve">
<value>v6tov4</value>
</data>
<data name="comboBox_type.Items3" xml:space="preserve">
<data name="comboBox_type.Items4" xml:space="preserve">
<value>v6tov6</value>
</data>
<data name="&gt;&gt;comboBox_type.Name" xml:space="preserve">
@ -453,4 +453,7 @@
<data name="textBox_listenPort.TextAlign" type="System.Windows.Forms.HorizontalAlignment, System.Windows.Forms">
<value>Center</value>
</data>
<data name="comboBox_type.Items" xml:space="preserve">
<value>(自动)</value>
</data>
</root>

View File

@ -14,7 +14,7 @@
<PackageTags>portproxy TCP/IP redirector</PackageTags>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<Copyright>Copyright © nstandard.net 2020</Copyright>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>