From 90223816d90b17a5ec76aeabca5b0dee1ead026f Mon Sep 17 00:00:00 2001 From: zmjack Date: Fri, 29 May 2020 03:32:44 +0800 Subject: [PATCH] v1.0.0 --- PortProxyGUI - FW/About.Designer.cs | 66 ++++++ PortProxyGUI - FW/About.cs | 22 ++ PortProxyGUI - FW/About.resx | 60 ++++++ PortProxyGUI - FW/NewProxy.Designer.cs | 196 ++++++++++++++++++ PortProxyGUI - FW/NewProxy.cs | 95 +++++++++ PortProxyGUI - FW/NewProxy.resx | 120 +++++++++++ PortProxyGUI - FW/PortProxyGUI - FW.csproj | 120 +++++++++++ PortProxyGUI - FW/PortProxyGUI.Designer.cs | 173 ++++++++++++++++ PortProxyGUI - FW/PortProxyGUI.cs | 125 +++++++++++ PortProxyGUI - FW/PortProxyGUI.resx | 123 +++++++++++ PortProxyGUI - FW/Program.cs | 19 ++ PortProxyGUI - FW/Properties/AssemblyInfo.cs | 35 ++++ .../Properties/Resources.Designer.cs | 63 ++++++ PortProxyGUI - FW/Properties/Resources.resx | 117 +++++++++++ .../Properties/Settings.Designer.cs | 26 +++ .../Properties/Settings.settings | 7 + PortProxyGUI - FW/app.manifest | 76 +++++++ .../CmdRunner.cs | 5 +- .../PortProxy.cs | 7 +- .../PortProxyGUI.Shared.projitems | 18 ++ .../PortProxyGUI.Shared.shproj | 13 ++ PortProxyGUI.Shared/ProxyType.cs | 28 +++ .../~extern/NStandard/XObject.cs | 23 ++ .../~extern/NStandard/XString.cs | 74 +++++++ PortProxyGUI.sln | 21 ++ PortProxyGUI/About.cs | 5 - PortProxyGUI/NewProxy.Designer.cs | 65 +++--- PortProxyGUI/NewProxy.cs | 14 +- PortProxyGUI/NewProxy.resx | 66 +++++- PortProxyGUI/PortProxyGUI.Designer.cs | 39 ++-- PortProxyGUI/PortProxyGUI.cs | 38 ++-- PortProxyGUI/PortProxyGUI.csproj | 39 +++- PortProxyGUI/PortProxyGUI.resx | 69 +++++- PortProxyGUI/Program.cs | 3 - 34 files changed, 1856 insertions(+), 114 deletions(-) create mode 100644 PortProxyGUI - FW/About.Designer.cs create mode 100644 PortProxyGUI - FW/About.cs create mode 100644 PortProxyGUI - FW/About.resx create mode 100644 PortProxyGUI - FW/NewProxy.Designer.cs create mode 100644 PortProxyGUI - FW/NewProxy.cs create mode 100644 PortProxyGUI - FW/NewProxy.resx create mode 100644 PortProxyGUI - FW/PortProxyGUI - FW.csproj create mode 100644 PortProxyGUI - FW/PortProxyGUI.Designer.cs create mode 100644 PortProxyGUI - FW/PortProxyGUI.cs create mode 100644 PortProxyGUI - FW/PortProxyGUI.resx create mode 100644 PortProxyGUI - FW/Program.cs create mode 100644 PortProxyGUI - FW/Properties/AssemblyInfo.cs create mode 100644 PortProxyGUI - FW/Properties/Resources.Designer.cs create mode 100644 PortProxyGUI - FW/Properties/Resources.resx create mode 100644 PortProxyGUI - FW/Properties/Settings.Designer.cs create mode 100644 PortProxyGUI - FW/Properties/Settings.settings create mode 100644 PortProxyGUI - FW/app.manifest rename {PortProxyGUI => PortProxyGUI.Shared}/CmdRunner.cs (86%) rename {PortProxyGUI => PortProxyGUI.Shared}/PortProxy.cs (67%) create mode 100644 PortProxyGUI.Shared/PortProxyGUI.Shared.projitems create mode 100644 PortProxyGUI.Shared/PortProxyGUI.Shared.shproj create mode 100644 PortProxyGUI.Shared/ProxyType.cs create mode 100644 PortProxyGUI.Shared/~extern/NStandard/XObject.cs create mode 100644 PortProxyGUI.Shared/~extern/NStandard/XString.cs diff --git a/PortProxyGUI - FW/About.Designer.cs b/PortProxyGUI - FW/About.Designer.cs new file mode 100644 index 0000000..93907c2 --- /dev/null +++ b/PortProxyGUI - FW/About.Designer.cs @@ -0,0 +1,66 @@ +namespace PortProxyGUI +{ + partial class About + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.linkLabel1 = new System.Windows.Forms.LinkLabel(); + this.SuspendLayout(); + // + // linkLabel1 + // + this.linkLabel1.Location = new System.Drawing.Point(12, 22); + this.linkLabel1.Name = "linkLabel1"; + this.linkLabel1.Size = new System.Drawing.Size(321, 23); + this.linkLabel1.TabIndex = 0; + this.linkLabel1.TabStop = true; + this.linkLabel1.Text = "https://github.com/zmjack/PortProxyGUI"; + this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.linkLabel1.Click += new System.EventHandler(this.linkLabel1_Click); + // + // About + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(345, 79); + this.Controls.Add(this.linkLabel1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "About"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "About"; + this.TopMost = true; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.LinkLabel linkLabel1; + } +} \ No newline at end of file diff --git a/PortProxyGUI - FW/About.cs b/PortProxyGUI - FW/About.cs new file mode 100644 index 0000000..4518176 --- /dev/null +++ b/PortProxyGUI - FW/About.cs @@ -0,0 +1,22 @@ +using System; +using System.Diagnostics; +using System.Windows.Forms; + +namespace PortProxyGUI +{ + public partial class About : Form + { + public About() + { + InitializeComponent(); + } + + private void linkLabel1_Click(object sender, EventArgs e) + { + if (sender is LinkLabel _sender) + { + Process.Start("explorer", _sender.Text); + } + } + } +} diff --git a/PortProxyGUI - FW/About.resx b/PortProxyGUI - FW/About.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/PortProxyGUI - FW/About.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PortProxyGUI - FW/NewProxy.Designer.cs b/PortProxyGUI - FW/NewProxy.Designer.cs new file mode 100644 index 0000000..d32282c --- /dev/null +++ b/PortProxyGUI - FW/NewProxy.Designer.cs @@ -0,0 +1,196 @@ +namespace PortProxyGUI +{ + partial class NewProxy + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.textBox_listenOn = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBox_connectTo = new System.Windows.Forms.TextBox(); + this.textBox_connectPort = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.textBox_listenPort = new System.Windows.Forms.TextBox(); + this.comboBox_type = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 11); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(59, 12); + this.label1.TabIndex = 0; + this.label1.Text = "Listen on"; + // + // textBox_listenOn + // + this.textBox_listenOn.Location = new System.Drawing.Point(79, 8); + this.textBox_listenOn.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBox_listenOn.Name = "textBox_listenOn"; + this.textBox_listenOn.Size = new System.Drawing.Size(103, 21); + this.textBox_listenOn.TabIndex = 0; + this.textBox_listenOn.Text = "*"; + this.textBox_listenOn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 35); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(65, 12); + this.label2.TabIndex = 0; + this.label2.Text = "Connect to"; + // + // textBox_connectTo + // + this.textBox_connectTo.Location = new System.Drawing.Point(79, 32); + this.textBox_connectTo.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBox_connectTo.Name = "textBox_connectTo"; + this.textBox_connectTo.Size = new System.Drawing.Size(103, 21); + this.textBox_connectTo.TabIndex = 3; + this.textBox_connectTo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // textBox_connectPort + // + this.textBox_connectPort.Location = new System.Drawing.Point(223, 32); + this.textBox_connectPort.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBox_connectPort.Name = "textBox_connectPort"; + this.textBox_connectPort.Size = new System.Drawing.Size(57, 21); + this.textBox_connectPort.TabIndex = 4; + this.textBox_connectPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(189, 35); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(29, 12); + this.label3.TabIndex = 0; + this.label3.Text = "Port"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(206, 62); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(74, 22); + this.button1.TabIndex = 6; + this.button1.Text = "Add"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(14, 66); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(29, 12); + this.label4.TabIndex = 0; + this.label4.Text = "Type"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(189, 11); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(29, 12); + this.label5.TabIndex = 0; + this.label5.Text = "Port"; + // + // textBox_listenPort + // + this.textBox_listenPort.Location = new System.Drawing.Point(223, 8); + this.textBox_listenPort.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBox_listenPort.Name = "textBox_listenPort"; + this.textBox_listenPort.Size = new System.Drawing.Size(57, 21); + this.textBox_listenPort.TabIndex = 2; + this.textBox_listenPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // comboBox_type + // + this.comboBox_type.FlatStyle = System.Windows.Forms.FlatStyle.Popup; + this.comboBox_type.FormattingEnabled = true; + this.comboBox_type.Items.AddRange(new object[] { + "v4tov4", + "v4tov6", + "v6tov4", + "v6tov6"}); + this.comboBox_type.Location = new System.Drawing.Point(78, 64); + this.comboBox_type.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBox_type.Name = "comboBox_type"; + this.comboBox_type.Size = new System.Drawing.Size(104, 20); + this.comboBox_type.TabIndex = 5; + // + // NewProxy + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(291, 90); + this.Controls.Add(this.comboBox_type); + this.Controls.Add(this.textBox_listenPort); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.button1); + this.Controls.Add(this.label3); + this.Controls.Add(this.textBox_connectPort); + this.Controls.Add(this.textBox_connectTo); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBox_listenOn); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "NewProxy"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "New Proxy"; + this.TopMost = true; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.NewProxy_FormClosing); + this.Load += new System.EventHandler(this.NewProxy_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox_listenOn; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBox_connectTo; + private System.Windows.Forms.TextBox textBox_connectPort; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.TextBox textBox_listenPort; + private System.Windows.Forms.ComboBox comboBox_type; + } +} \ No newline at end of file diff --git a/PortProxyGUI - FW/NewProxy.cs b/PortProxyGUI - FW/NewProxy.cs new file mode 100644 index 0000000..3f97403 --- /dev/null +++ b/PortProxyGUI - FW/NewProxy.cs @@ -0,0 +1,95 @@ +using PortProxyGUI._extern.NStandard; +using System; +using System.Text.RegularExpressions; +using System.Windows.Forms; + +namespace PortProxyGUI +{ + public partial class NewProxy : Form + { + public readonly PortProxyGUI PortProxyGUI; + + public NewProxy(PortProxyGUI portProxyGUI) + { + PortProxyGUI = portProxyGUI; + + InitializeComponent(); + } + + private void AddPortProxy(string type, string listenOn, string listenPort, string connectTo, string connectPort) + { + var output = CmdRunner.Execute($"netsh interface portproxy add {type} listenaddress={listenOn} listenport={listenPort} connectaddress={connectTo} connectport={connectPort}"); + Invoke((Action)(() => PortProxyGUI.RefreshProxyList())); + } + + private void button1_Click(object sender, EventArgs e) + { + var type = comboBox_type.Text; + var listenOn = textBox_listenOn.Text; + var connectTo = textBox_connectTo.Text; + var listenPort = textBox_listenPort.Text; + var connectPort = textBox_connectPort.Text; + + if (!int.TryParse(listenPort, out var _listenPort) || _listenPort < 0 || _listenPort > 65535) + { + MessageBox.Show($"The listen port is invalid.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + if (!int.TryParse(connectPort, out var _connectPort) || _connectPort < 0 || _connectPort > 65535) + { + MessageBox.Show($"The connect port is invalid.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + var listenOn_any = listenOn == "*"; + var listenOn_ipv4 = listenOn.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}$")); + var listenOn_ipv6 = listenOn.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$")); + var connectTo_ipv4 = connectTo.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}$")); + var connectTo_ipv6 = connectTo.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$")); + + if (!listenOn_any && !listenOn_ipv4 && !listenOn_ipv6) + { + MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + if (!connectTo_ipv4 && !connectTo_ipv6) + { + MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + if (listenOn_any && connectTo_ipv4 && !type.EndsWith("v4")) + { + MessageBox.Show($"The type must be v4tov4 or v6tov4.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + else if (listenOn_any && connectTo_ipv6 && !type.EndsWith("v6")) + { + MessageBox.Show($"The type must be v4tov6 or v6tov6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + else + { + if (listenOn_ipv4 && connectTo_ipv4) type = comboBox_type.Text = "v4tov4"; + else if (listenOn_ipv4 && connectTo_ipv6) type = comboBox_type.Text = "v4tov6"; + else if (listenOn_ipv6 && connectTo_ipv4) type = comboBox_type.Text = "v6tov4"; + else if (listenOn_ipv6 && connectTo_ipv6) type = comboBox_type.Text = "v6tov6"; + } + + AddPortProxy(type, listenOn, listenPort, connectTo, connectPort); + } + + private void NewProxy_Load(object sender, EventArgs e) + { + + } + + private void NewProxy_FormClosing(object sender, FormClosingEventArgs e) + { + PortProxyGUI.NewProxyForm = null; + } + + } +} diff --git a/PortProxyGUI - FW/NewProxy.resx b/PortProxyGUI - FW/NewProxy.resx new file mode 100644 index 0000000..7080a7d --- /dev/null +++ b/PortProxyGUI - FW/NewProxy.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PortProxyGUI - FW/PortProxyGUI - FW.csproj b/PortProxyGUI - FW/PortProxyGUI - FW.csproj new file mode 100644 index 0000000..0767c08 --- /dev/null +++ b/PortProxyGUI - FW/PortProxyGUI - FW.csproj @@ -0,0 +1,120 @@ + + + + + Debug + AnyCPU + {1B166039-E98C-404A-89A5-C981364B5546} + WinExe + PortProxyGUI + PortProxyGUI + v3.5 + 512 + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + Form + + + About.cs + + + Form + + + NewProxy.cs + + + Form + + + PortProxyGUI.cs + + + + + About.cs + + + NewProxy.cs + + + PortProxyGUI.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + False + .NET Framework 3.5 SP1 + true + + + + + \ No newline at end of file diff --git a/PortProxyGUI - FW/PortProxyGUI.Designer.cs b/PortProxyGUI - FW/PortProxyGUI.Designer.cs new file mode 100644 index 0000000..0dca9fb --- /dev/null +++ b/PortProxyGUI - FW/PortProxyGUI.Designer.cs @@ -0,0 +1,173 @@ +namespace PortProxyGUI +{ + partial class PortProxyGUI + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.listView1 = new System.Windows.Forms.ListView(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); + this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.contextMenuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // listView1 + // + this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeader1, + this.columnHeader2, + this.columnHeader3, + this.columnHeader4, + this.columnHeader5}); + this.listView1.ContextMenuStrip = this.contextMenuStrip1; + this.listView1.Dock = System.Windows.Forms.DockStyle.Fill; + this.listView1.FullRowSelect = true; + this.listView1.HideSelection = false; + this.listView1.Location = new System.Drawing.Point(0, 0); + this.listView1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.listView1.Name = "listView1"; + this.listView1.Size = new System.Drawing.Size(573, 262); + this.listView1.TabIndex = 0; + this.listView1.UseCompatibleStateImageBehavior = false; + this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseUp); + // + // columnHeader1 + // + this.columnHeader1.Text = "Type"; + // + // columnHeader2 + // + this.columnHeader2.Text = "Listen on"; + this.columnHeader2.Width = 140; + // + // columnHeader3 + // + this.columnHeader3.Text = "Listen port"; + this.columnHeader3.Width = 100; + // + // columnHeader4 + // + this.columnHeader4.Text = "Connect to"; + this.columnHeader4.Width = 140; + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.toolStripMenuItem2, + this.toolStripSeparator1, + this.toolStripMenuItem3, + this.toolStripSeparator2, + this.toolStripMenuItem4}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(121, 104); + this.contextMenuStrip1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.contextMenuStrip1_MouseClick); + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(120, 22); + this.toolStripMenuItem1.Text = "New"; + // + // toolStripMenuItem2 + // + this.toolStripMenuItem2.Name = "toolStripMenuItem2"; + this.toolStripMenuItem2.Size = new System.Drawing.Size(120, 22); + this.toolStripMenuItem2.Text = "Delete"; + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(117, 6); + // + // toolStripMenuItem3 + // + this.toolStripMenuItem3.Name = "toolStripMenuItem3"; + this.toolStripMenuItem3.Size = new System.Drawing.Size(120, 22); + this.toolStripMenuItem3.Text = "Refresh"; + // + // toolStripSeparator2 + // + this.toolStripSeparator2.Name = "toolStripSeparator2"; + this.toolStripSeparator2.Size = new System.Drawing.Size(117, 6); + // + // toolStripMenuItem4 + // + this.toolStripMenuItem4.Name = "toolStripMenuItem4"; + this.toolStripMenuItem4.Size = new System.Drawing.Size(120, 22); + this.toolStripMenuItem4.Text = "About"; + // + // columnHeader5 + // + this.columnHeader5.Text = "Connect port"; + this.columnHeader5.Width = 100; + // + // PortProxyGUI + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(573, 262); + this.Controls.Add(this.listView1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "PortProxyGUI"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Port Proxy GUI"; + this.Load += new System.EventHandler(this.PortProxyGUI_Load); + this.contextMenuStrip1.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ListView listView1; + private System.Windows.Forms.ColumnHeader columnHeader1; + private System.Windows.Forms.ColumnHeader columnHeader2; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; + private System.Windows.Forms.ColumnHeader columnHeader3; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem3; + private System.Windows.Forms.ColumnHeader columnHeader4; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4; + private System.Windows.Forms.ColumnHeader columnHeader5; + } +} + diff --git a/PortProxyGUI - FW/PortProxyGUI.cs b/PortProxyGUI - FW/PortProxyGUI.cs new file mode 100644 index 0000000..9d6145a --- /dev/null +++ b/PortProxyGUI - FW/PortProxyGUI.cs @@ -0,0 +1,125 @@ +using PortProxyGUI._extern.NStandard; +using System; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; +using System.Windows.Forms; +using static System.Windows.Forms.ListViewItem; + +namespace PortProxyGUI +{ + public partial class PortProxyGUI : Form + { + public NewProxy NewProxyForm; + public About AboutForm; + + public PortProxyGUI() + { + InitializeComponent(); + } + + private void PortProxyGUI_Load(object sender, EventArgs e) + { + RefreshProxyList(); + } + + private void DeleteSelectedProxies() + { + var items = listView1.SelectedItems.OfType(); + foreach (var item in items) + { + var subItems = item.SubItems.OfType().ToArray(); + var type = subItems[0].Text; + var listenOn= subItems[1].Text; + var listenPort = subItems[2].Text; + var output = CmdRunner.Execute($"netsh interface portproxy delete {type} listenaddress={listenOn} listenport={listenPort}"); + } + + RefreshProxyList(); + } + + public void RefreshProxyList() + { + var output = CmdRunner.Execute("netsh interface portproxy show all"); + var types = new[] + { + new ProxyType("ipv4", "ipv4"), + new ProxyType("ipv4", "ipv6"), + new ProxyType("ipv6", "ipv4"), + new ProxyType("ipv6", "ipv6"), + }; + + var proxies = types.SelectMany(type => + { + var typeProxies = output + .Project(new Regex($@"{type.From}:[^\n]+?{type.To}:\r\n\r\n.+?\r\n--------------- ---------- --------------- ----------\r\n(.+?)\r\n\r\n", RegexOptions.Singleline)) + ?.Split(new[] { Environment.NewLine }, StringSplitOptions.None) + .Select(line => + { + var parts = line.Resolve(new Regex(@"^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$")); + return new PortProxy + { + Type = type.Type, + ListenOn = parts[1].FirstOrDefault(), + ListenPort = parts[2].FirstOrDefault(), + ConnectTo = parts[3].FirstOrDefault(), + ConnectPort = parts[4].FirstOrDefault(), + }; + }); + return typeProxies ?? new PortProxy[0]; + }); + + listView1.Items.Clear(); + foreach (var proxy in proxies) + { + listView1.Items.Add(new ListViewItem(proxy.Type).Then(vitem => + { + vitem.SubItems.AddRange(new[] { proxy.ListenOn, proxy.ListenPort, proxy.ConnectTo, proxy.ConnectPort }); + })); + } + } + + private void contextMenuStrip1_MouseClick(object sender, MouseEventArgs e) + { + if (sender is ContextMenuStrip _sender) + { + var selected = _sender.Items.OfType().Where(x => x.Selected).FirstOrDefault(); + if (selected is null || !selected.Enabled) return; + + switch (selected.Text) + { + case "New": + if (NewProxyForm == null) + { + NewProxyForm = new NewProxy(this); + NewProxyForm.Show(); + } + else NewProxyForm.Show(); + break; + + case "Refresh": RefreshProxyList(); break; + case "Delete": DeleteSelectedProxies(); break; + + case "About": + if (AboutForm == null) + { + AboutForm = new About(); + AboutForm.Show(); + } + else AboutForm.Show(); + break; + } + } + } + + private void listView1_MouseUp(object sender, MouseEventArgs e) + { + if (sender is ListView _sender) + { + if (e.Button == MouseButtons.Right && _sender.SelectedItems.OfType().Any()) + toolStripMenuItem2.Enabled = true; + else toolStripMenuItem2.Enabled = false; + } + } + } +} diff --git a/PortProxyGUI - FW/PortProxyGUI.resx b/PortProxyGUI - FW/PortProxyGUI.resx new file mode 100644 index 0000000..73b0127 --- /dev/null +++ b/PortProxyGUI - FW/PortProxyGUI.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/PortProxyGUI - FW/Program.cs b/PortProxyGUI - FW/Program.cs new file mode 100644 index 0000000..6d882c9 --- /dev/null +++ b/PortProxyGUI - FW/Program.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace PortProxyGUI +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new PortProxyGUI()); + } + } +} diff --git a/PortProxyGUI - FW/Properties/AssemblyInfo.cs b/PortProxyGUI - FW/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..716ffb5 --- /dev/null +++ b/PortProxyGUI - FW/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("PortProxyGUI - FW")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PortProxyGUI - FW")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1b166039-e98c-404a-89a5-c981364b5546")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PortProxyGUI - FW/Properties/Resources.Designer.cs b/PortProxyGUI - FW/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0edb72f --- /dev/null +++ b/PortProxyGUI - FW/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PortProxyGUI.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PortProxyGUI.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/PortProxyGUI - FW/Properties/Resources.resx b/PortProxyGUI - FW/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/PortProxyGUI - FW/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/PortProxyGUI - FW/Properties/Settings.Designer.cs b/PortProxyGUI - FW/Properties/Settings.Designer.cs new file mode 100644 index 0000000..62dbe99 --- /dev/null +++ b/PortProxyGUI - FW/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PortProxyGUI.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.6.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/PortProxyGUI - FW/Properties/Settings.settings b/PortProxyGUI - FW/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/PortProxyGUI - FW/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/PortProxyGUI - FW/app.manifest b/PortProxyGUI - FW/app.manifest new file mode 100644 index 0000000..169e618 --- /dev/null +++ b/PortProxyGUI - FW/app.manifest @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PortProxyGUI/CmdRunner.cs b/PortProxyGUI.Shared/CmdRunner.cs similarity index 86% rename from PortProxyGUI/CmdRunner.cs rename to PortProxyGUI.Shared/CmdRunner.cs index b25b90c..5d3c62e 100644 --- a/PortProxyGUI/CmdRunner.cs +++ b/PortProxyGUI.Shared/CmdRunner.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Text; +using System.Diagnostics; namespace PortProxyGUI { diff --git a/PortProxyGUI/PortProxy.cs b/PortProxyGUI.Shared/PortProxy.cs similarity index 67% rename from PortProxyGUI/PortProxy.cs rename to PortProxyGUI.Shared/PortProxy.cs index c61078f..ef9fc6c 100644 --- a/PortProxyGUI/PortProxy.cs +++ b/PortProxyGUI.Shared/PortProxy.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; - -namespace PortProxyGUI +namespace PortProxyGUI { public class PortProxy { diff --git a/PortProxyGUI.Shared/PortProxyGUI.Shared.projitems b/PortProxyGUI.Shared/PortProxyGUI.Shared.projitems new file mode 100644 index 0000000..7f9be85 --- /dev/null +++ b/PortProxyGUI.Shared/PortProxyGUI.Shared.projitems @@ -0,0 +1,18 @@ + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + b38ef2b9-e38d-4d6d-bf0d-7c1934d6cfdc + + + PortProxyGUI.Shared + + + + + + + + + \ No newline at end of file diff --git a/PortProxyGUI.Shared/PortProxyGUI.Shared.shproj b/PortProxyGUI.Shared/PortProxyGUI.Shared.shproj new file mode 100644 index 0000000..f04ef6e --- /dev/null +++ b/PortProxyGUI.Shared/PortProxyGUI.Shared.shproj @@ -0,0 +1,13 @@ + + + + b38ef2b9-e38d-4d6d-bf0d-7c1934d6cfdc + 14.0 + + + + + + + + diff --git a/PortProxyGUI.Shared/ProxyType.cs b/PortProxyGUI.Shared/ProxyType.cs new file mode 100644 index 0000000..b157a51 --- /dev/null +++ b/PortProxyGUI.Shared/ProxyType.cs @@ -0,0 +1,28 @@ +using System; + +namespace PortProxyGUI +{ + public class ProxyType + { + public ProxyType(string from, string to) + { + From = from; + To = to; + } + + public string From { get; set; } + public string To { get; set; } + public string Type + { + get + { + if (From == "ipv4" && To == "ipv4") return "v4tov4"; + if (From == "ipv4" && To == "ipv6") return "v4tov6"; + if (From == "ipv6" && To == "ipv4") return "v6tov4"; + if (From == "ipv6" && To == "ipv6") return "v6tov6"; + throw new NotSupportedException(); + } + } + + } +} diff --git a/PortProxyGUI.Shared/~extern/NStandard/XObject.cs b/PortProxyGUI.Shared/~extern/NStandard/XObject.cs new file mode 100644 index 0000000..e023a6c --- /dev/null +++ b/PortProxyGUI.Shared/~extern/NStandard/XObject.cs @@ -0,0 +1,23 @@ +using System; +using System.ComponentModel; + +namespace PortProxyGUI._extern.NStandard +{ + [EditorBrowsable(EditorBrowsableState.Never)] + public static class XObject + { + /// + /// Do a task for itself, then return itself. + /// + /// + /// + /// + /// + public static TSelf Then(this TSelf @this, Action task) + { + task(@this); + return @this; + } + + } +} diff --git a/PortProxyGUI.Shared/~extern/NStandard/XString.cs b/PortProxyGUI.Shared/~extern/NStandard/XString.cs new file mode 100644 index 0000000..3c05395 --- /dev/null +++ b/PortProxyGUI.Shared/~extern/NStandard/XString.cs @@ -0,0 +1,74 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Text.RegularExpressions; + +namespace PortProxyGUI._extern.NStandard +{ + [EditorBrowsable(EditorBrowsableState.Never)] + public static class XString + { + /// + /// Indicates whether the string matches the specified regular expression. + /// + /// + /// + /// + public static bool IsMatch(this string @this, Regex regex) => regex.Match(@this).Success; + + /// + /// Projects the specified string to a new string by using regular expressions. + /// If there is no match, this method returns null. + /// + /// + /// + /// + /// + public static string Project(this string @this, Regex regex, string target = null) + { + var match = regex.Match(@this); + if (match.Success) + { + if (target is null) + return string.Join("", match.Groups.OfType().Skip(1).Select(g => g.Value).ToArray()); + else return regex.Replace(match.Groups[0].Value, target); + } + else return null; + } + + /// + /// Projects the specified string to an array by using regular expressions. + /// + /// + /// + /// + public static string[][] Resolve(this string @this, Regex regex) + { + if (TryResolve(@this, regex, out var ret)) return ret; + else throw new ArgumentNullException("Can not match the sepecifed Regex."); + } + + /// + /// Projects the specified string to an array by using regular expressions. + /// + /// + /// + /// + public static bool TryResolve(this string @this, Regex regex, out string[][] ret) + { + var match = regex.Match(@this); + if (match.Success) + { + ret = match.Groups.OfType() + .Select(g => g.Captures.OfType().Select(c => c.Value).ToArray()).ToArray(); + return true; + } + else + { + ret = null; + return false; + } + } + + } +} diff --git a/PortProxyGUI.sln b/PortProxyGUI.sln index 0f58ed7..c41f8fb 100644 --- a/PortProxyGUI.sln +++ b/PortProxyGUI.sln @@ -5,7 +5,16 @@ VisualStudioVersion = 16.0.30114.105 MinimumVisualStudioVersion = 15.0.26124.0 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortProxyGUI", "PortProxyGUI\PortProxyGUI.csproj", "{7459E9F4-8B98-42D6-92CF-E90961E05C90}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortProxyGUI - FW", "PortProxyGUI - FW\PortProxyGUI - FW.csproj", "{1B166039-E98C-404A-89A5-C981364B5546}" +EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "PortProxyGUI.Shared", "PortProxyGUI.Shared\PortProxyGUI.Shared.shproj", "{B38EF2B9-E38D-4D6D-BF0D-7C1934D6CFDC}" +EndProject Global + GlobalSection(SharedMSBuildProjectFiles) = preSolution + PortProxyGUI.Shared\PortProxyGUI.Shared.projitems*{1b166039-e98c-404a-89a5-c981364b5546}*SharedItemsImports = 4 + PortProxyGUI.Shared\PortProxyGUI.Shared.projitems*{7459e9f4-8b98-42d6-92cf-e90961e05c90}*SharedItemsImports = 5 + PortProxyGUI.Shared\PortProxyGUI.Shared.projitems*{b38ef2b9-e38d-4d6d-bf0d-7c1934d6cfdc}*SharedItemsImports = 13 + EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 @@ -27,6 +36,18 @@ Global {7459E9F4-8B98-42D6-92CF-E90961E05C90}.Release|x64.Build.0 = Release|Any CPU {7459E9F4-8B98-42D6-92CF-E90961E05C90}.Release|x86.ActiveCfg = Release|Any CPU {7459E9F4-8B98-42D6-92CF-E90961E05C90}.Release|x86.Build.0 = Release|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Debug|x64.ActiveCfg = Debug|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Debug|x64.Build.0 = Debug|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Debug|x86.ActiveCfg = Debug|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Debug|x86.Build.0 = Debug|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Release|Any CPU.Build.0 = Release|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Release|x64.ActiveCfg = Release|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Release|x64.Build.0 = Release|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Release|x86.ActiveCfg = Release|Any CPU + {1B166039-E98C-404A-89A5-C981364B5546}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PortProxyGUI/About.cs b/PortProxyGUI/About.cs index 93b7409..4518176 100644 --- a/PortProxyGUI/About.cs +++ b/PortProxyGUI/About.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Diagnostics; -using System.Drawing; -using System.Text; using System.Windows.Forms; namespace PortProxyGUI diff --git a/PortProxyGUI/NewProxy.Designer.cs b/PortProxyGUI/NewProxy.Designer.cs index a567fb2..d32282c 100644 --- a/PortProxyGUI/NewProxy.Designer.cs +++ b/PortProxyGUI/NewProxy.Designer.cs @@ -44,19 +44,18 @@ // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(15, 15); - this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Location = new System.Drawing.Point(13, 11); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(60, 17); + this.label1.Size = new System.Drawing.Size(59, 12); this.label1.TabIndex = 0; this.label1.Text = "Listen on"; // // textBox_listenOn // - this.textBox_listenOn.Location = new System.Drawing.Point(92, 12); - this.textBox_listenOn.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.textBox_listenOn.Location = new System.Drawing.Point(79, 8); + this.textBox_listenOn.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBox_listenOn.Name = "textBox_listenOn"; - this.textBox_listenOn.Size = new System.Drawing.Size(120, 23); + this.textBox_listenOn.Size = new System.Drawing.Size(103, 21); this.textBox_listenOn.TabIndex = 0; this.textBox_listenOn.Text = "*"; this.textBox_listenOn.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; @@ -64,47 +63,44 @@ // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(15, 49); - this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Location = new System.Drawing.Point(13, 35); this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(71, 17); + this.label2.Size = new System.Drawing.Size(65, 12); this.label2.TabIndex = 0; this.label2.Text = "Connect to"; // // textBox_connectTo // - this.textBox_connectTo.Location = new System.Drawing.Point(92, 46); - this.textBox_connectTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.textBox_connectTo.Location = new System.Drawing.Point(79, 32); + this.textBox_connectTo.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBox_connectTo.Name = "textBox_connectTo"; - this.textBox_connectTo.Size = new System.Drawing.Size(120, 23); + this.textBox_connectTo.Size = new System.Drawing.Size(103, 21); this.textBox_connectTo.TabIndex = 3; this.textBox_connectTo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // textBox_connectPort // - this.textBox_connectPort.Location = new System.Drawing.Point(260, 46); - this.textBox_connectPort.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.textBox_connectPort.Location = new System.Drawing.Point(223, 32); + this.textBox_connectPort.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBox_connectPort.Name = "textBox_connectPort"; - this.textBox_connectPort.Size = new System.Drawing.Size(66, 23); + this.textBox_connectPort.Size = new System.Drawing.Size(57, 21); this.textBox_connectPort.TabIndex = 4; this.textBox_connectPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(220, 49); - this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Location = new System.Drawing.Point(189, 35); this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(32, 17); + this.label3.Size = new System.Drawing.Size(29, 12); this.label3.TabIndex = 0; this.label3.Text = "Port"; // // button1 // - this.button1.Location = new System.Drawing.Point(240, 88); - this.button1.Margin = new System.Windows.Forms.Padding(4); + this.button1.Location = new System.Drawing.Point(206, 62); this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(86, 26); + this.button1.Size = new System.Drawing.Size(74, 22); this.button1.TabIndex = 6; this.button1.Text = "Add"; this.button1.UseVisualStyleBackColor = true; @@ -113,29 +109,27 @@ // label4 // this.label4.AutoSize = true; - this.label4.Location = new System.Drawing.Point(16, 93); - this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Location = new System.Drawing.Point(14, 66); this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(36, 17); + this.label4.Size = new System.Drawing.Size(29, 12); this.label4.TabIndex = 0; this.label4.Text = "Type"; // // label5 // this.label5.AutoSize = true; - this.label5.Location = new System.Drawing.Point(220, 15); - this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Location = new System.Drawing.Point(189, 11); this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(32, 17); + this.label5.Size = new System.Drawing.Size(29, 12); this.label5.TabIndex = 0; this.label5.Text = "Port"; // // textBox_listenPort // - this.textBox_listenPort.Location = new System.Drawing.Point(260, 12); - this.textBox_listenPort.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.textBox_listenPort.Location = new System.Drawing.Point(223, 8); + this.textBox_listenPort.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.textBox_listenPort.Name = "textBox_listenPort"; - this.textBox_listenPort.Size = new System.Drawing.Size(66, 23); + this.textBox_listenPort.Size = new System.Drawing.Size(57, 21); this.textBox_listenPort.TabIndex = 2; this.textBox_listenPort.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // @@ -148,16 +142,17 @@ "v4tov6", "v6tov4", "v6tov6"}); - this.comboBox_type.Location = new System.Drawing.Point(91, 90); + this.comboBox_type.Location = new System.Drawing.Point(78, 64); + this.comboBox_type.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.comboBox_type.Name = "comboBox_type"; - this.comboBox_type.Size = new System.Drawing.Size(121, 25); + this.comboBox_type.Size = new System.Drawing.Size(104, 20); this.comboBox_type.TabIndex = 5; // // NewProxy // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(339, 128); + this.ClientSize = new System.Drawing.Size(291, 90); this.Controls.Add(this.comboBox_type); this.Controls.Add(this.textBox_listenPort); this.Controls.Add(this.label5); @@ -170,7 +165,7 @@ this.Controls.Add(this.textBox_listenOn); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; - this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "NewProxy"; diff --git a/PortProxyGUI/NewProxy.cs b/PortProxyGUI/NewProxy.cs index e0d55ea..3f97403 100644 --- a/PortProxyGUI/NewProxy.cs +++ b/PortProxyGUI/NewProxy.cs @@ -1,11 +1,5 @@ -using NStandard; +using PortProxyGUI._extern.NStandard; using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Runtime.InteropServices.ComTypes; -using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -36,12 +30,6 @@ namespace PortProxyGUI var listenPort = textBox_listenPort.Text; var connectPort = textBox_connectPort.Text; - if (!comboBox_type.Items.Contains(type)) - { - MessageBox.Show($"The type is invalid.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); - return; - } - if (!int.TryParse(listenPort, out var _listenPort) || _listenPort < 0 || _listenPort > 65535) { MessageBox.Show($"The listen port is invalid.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); diff --git a/PortProxyGUI/NewProxy.resx b/PortProxyGUI/NewProxy.resx index f298a7b..7080a7d 100644 --- a/PortProxyGUI/NewProxy.resx +++ b/PortProxyGUI/NewProxy.resx @@ -1,4 +1,64 @@ - + + + @@ -52,9 +112,9 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 \ No newline at end of file diff --git a/PortProxyGUI/PortProxyGUI.Designer.cs b/PortProxyGUI/PortProxyGUI.Designer.cs index c80ddf7..0dca9fb 100644 --- a/PortProxyGUI/PortProxyGUI.Designer.cs +++ b/PortProxyGUI/PortProxyGUI.Designer.cs @@ -30,10 +30,10 @@ { this.components = new System.ComponentModel.Container(); this.listView1 = new System.Windows.Forms.ListView(); - this.columnHeader1 = new System.Windows.Forms.ColumnHeader(); - this.columnHeader2 = new System.Windows.Forms.ColumnHeader(); - this.columnHeader3 = new System.Windows.Forms.ColumnHeader(); - this.columnHeader4 = new System.Windows.Forms.ColumnHeader(); + this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); @@ -41,6 +41,7 @@ this.toolStripMenuItem3 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripMenuItem(); + this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -50,14 +51,16 @@ this.columnHeader1, this.columnHeader2, this.columnHeader3, - this.columnHeader4}); + this.columnHeader4, + this.columnHeader5}); this.listView1.ContextMenuStrip = this.contextMenuStrip1; this.listView1.Dock = System.Windows.Forms.DockStyle.Fill; this.listView1.FullRowSelect = true; this.listView1.HideSelection = false; this.listView1.Location = new System.Drawing.Point(0, 0); + this.listView1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.listView1.Name = "listView1"; - this.listView1.Size = new System.Drawing.Size(460, 230); + this.listView1.Size = new System.Drawing.Size(573, 262); this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; @@ -66,22 +69,21 @@ // columnHeader1 // this.columnHeader1.Text = "Type"; - this.columnHeader1.Width = 80; // // columnHeader2 // - this.columnHeader2.Text = "Listen port"; - this.columnHeader2.Width = 100; + this.columnHeader2.Text = "Listen on"; + this.columnHeader2.Width = 140; // // columnHeader3 // - this.columnHeader3.Text = "Connect to"; - this.columnHeader3.Width = 160; + this.columnHeader3.Text = "Listen port"; + this.columnHeader3.Width = 100; // // columnHeader4 // - this.columnHeader4.Text = "Connect port"; - this.columnHeader4.Width = 100; + this.columnHeader4.Text = "Connect to"; + this.columnHeader4.Width = 140; // // contextMenuStrip1 // @@ -130,12 +132,18 @@ this.toolStripMenuItem4.Size = new System.Drawing.Size(120, 22); this.toolStripMenuItem4.Text = "About"; // + // columnHeader5 + // + this.columnHeader5.Text = "Connect port"; + this.columnHeader5.Width = 100; + // // PortProxyGUI // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(460, 230); + this.ClientSize = new System.Drawing.Size(573, 262); this.Controls.Add(this.listView1); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "PortProxyGUI"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Port Proxy GUI"; @@ -159,6 +167,7 @@ private System.Windows.Forms.ColumnHeader columnHeader4; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem4; + private System.Windows.Forms.ColumnHeader columnHeader5; } } diff --git a/PortProxyGUI/PortProxyGUI.cs b/PortProxyGUI/PortProxyGUI.cs index 9112742..9d6145a 100644 --- a/PortProxyGUI/PortProxyGUI.cs +++ b/PortProxyGUI/PortProxyGUI.cs @@ -1,13 +1,8 @@ -using NStandard; +using PortProxyGUI._extern.NStandard; using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Data; -using System.Drawing; using System.Linq; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; using System.Windows.Forms; using static System.Windows.Forms.ListViewItem; @@ -35,8 +30,9 @@ namespace PortProxyGUI { var subItems = item.SubItems.OfType().ToArray(); var type = subItems[0].Text; - var listenPort = subItems[1].Text; - var output = CmdRunner.Execute($"netsh interface portproxy delete {type} listenport={listenPort}"); + var listenOn= subItems[1].Text; + var listenPort = subItems[2].Text; + var output = CmdRunner.Execute($"netsh interface portproxy delete {type} listenaddress={listenOn} listenport={listenPort}"); } RefreshProxyList(); @@ -45,29 +41,25 @@ namespace PortProxyGUI public void RefreshProxyList() { var output = CmdRunner.Execute("netsh interface portproxy show all"); - var types = new[] { ("ipv4", "ipv4"), ("ipv4", "ipv6"), ("ipv6", "ipv4"), ("ipv6", "ipv6") }; + var types = new[] + { + new ProxyType("ipv4", "ipv4"), + new ProxyType("ipv4", "ipv6"), + new ProxyType("ipv6", "ipv4"), + new ProxyType("ipv6", "ipv6"), + }; var proxies = types.SelectMany(type => { - var from = type.Item1; - var to = type.Item2; - var typeProxies = output - .Project(new Regex($@"{from}:[^\n]+?{to}:\r\n\r\n.+?\r\n--------------- ---------- --------------- ----------\r\n(.+?)\r\n\r\n", RegexOptions.Singleline)) - ?.Split(Environment.NewLine) + .Project(new Regex($@"{type.From}:[^\n]+?{type.To}:\r\n\r\n.+?\r\n--------------- ---------- --------------- ----------\r\n(.+?)\r\n\r\n", RegexOptions.Singleline)) + ?.Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select(line => { var parts = line.Resolve(new Regex(@"^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$")); return new PortProxy { - Type = (from, to) switch - { - ("ipv4", "ipv4") => "v4tov4", - ("ipv4", "ipv6") => "v4tov6", - ("ipv6", "ipv4") => "v6tov4", - ("ipv6", "ipv6") => "v6tov6", - _ => throw new NotSupportedException(), - }, + Type = type.Type, ListenOn = parts[1].FirstOrDefault(), ListenPort = parts[2].FirstOrDefault(), ConnectTo = parts[3].FirstOrDefault(), @@ -82,7 +74,7 @@ namespace PortProxyGUI { listView1.Items.Add(new ListViewItem(proxy.Type).Then(vitem => { - vitem.SubItems.AddRange(new[] { proxy.ListenPort, proxy.ConnectTo, proxy.ConnectPort }); + vitem.SubItems.AddRange(new[] { proxy.ListenOn, proxy.ListenPort, proxy.ConnectTo, proxy.ConnectPort }); })); } } diff --git a/PortProxyGUI/PortProxyGUI.csproj b/PortProxyGUI/PortProxyGUI.csproj index e3b87b6..813bbb0 100644 --- a/PortProxyGUI/PortProxyGUI.csproj +++ b/PortProxyGUI/PortProxyGUI.csproj @@ -16,10 +16,6 @@ Copyright © nstandard.net 2020 - - - - True @@ -27,4 +23,39 @@ + + + Form + + + About.cs + + + Form + + + NewProxy.cs + + + Form + + + PortProxyGUI.cs + + + + + + About.cs + + + NewProxy.cs + + + PortProxyGUI.cs + + + + + \ No newline at end of file diff --git a/PortProxyGUI/PortProxyGUI.resx b/PortProxyGUI/PortProxyGUI.resx index f298a7b..73b0127 100644 --- a/PortProxyGUI/PortProxyGUI.resx +++ b/PortProxyGUI/PortProxyGUI.resx @@ -1,4 +1,64 @@ - + + + @@ -52,9 +112,12 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/PortProxyGUI/Program.cs b/PortProxyGUI/Program.cs index fd685b7..f4a74cb 100644 --- a/PortProxyGUI/Program.cs +++ b/PortProxyGUI/Program.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; namespace PortProxyGUI