This commit is contained in:
zmjack 2020-05-29 00:57:32 +08:00
parent fea2c5456a
commit c1e1f294f5
16 changed files with 1095 additions and 0 deletions

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 zmjack
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

37
PortProxyGUI.sln Normal file
View File

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Debug|x64.ActiveCfg = Debug|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Debug|x64.Build.0 = Debug|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Debug|x86.ActiveCfg = Debug|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Debug|x86.Build.0 = Debug|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Release|Any CPU.Build.0 = Release|Any CPU
{7459E9F4-8B98-42D6-92CF-E90961E05C90}.Release|x64.ActiveCfg = Release|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {780FB421-FE6E-4520-94A0-A0CD31310C27}
EndGlobalSection
EndGlobal

65
PortProxyGUI/About.Designer.cs generated Normal file
View File

@ -0,0 +1,65 @@
namespace PortProxyGUI
{
partial class About
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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.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;
}
}

27
PortProxyGUI/About.cs Normal file
View File

@ -0,0 +1,27 @@
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
{
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);
}
}
}
}

60
PortProxyGUI/About.resx Normal file
View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

28
PortProxyGUI/CmdRunner.cs Normal file
View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace PortProxyGUI
{
public static class CmdRunner
{
public static string Execute(string cmd)
{
var proc = Process.Start(new ProcessStartInfo
{
FileName = "cmd",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
});
proc.Start();
proc.StandardInput.WriteLine($"{cmd} & exit");
var output = proc.StandardOutput.ReadToEnd();
return output;
}
}
}

201
PortProxyGUI/NewProxy.Designer.cs generated Normal file
View File

@ -0,0 +1,201 @@
namespace PortProxyGUI
{
partial class NewProxy
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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(15, 15);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 17);
this.label1.TabIndex = 0;
this.label1.Text = "Listen on";
//
// textBox_listenOn
//
this.textBox_listenOn.Enabled = false;
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.Name = "textBox_listenOn";
this.textBox_listenOn.Size = new System.Drawing.Size(120, 23);
this.textBox_listenOn.TabIndex = 1;
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(15, 49);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 17);
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.Name = "textBox_connectTo";
this.textBox_connectTo.Size = new System.Drawing.Size(120, 23);
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.Name = "textBox_connectPort";
this.textBox_connectPort.Size = new System.Drawing.Size(66, 23);
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.Name = "label3";
this.label3.Size = new System.Drawing.Size(32, 17);
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.Name = "button1";
this.button1.Size = new System.Drawing.Size(86, 26);
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(16, 93);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(36, 17);
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.Name = "label5";
this.label5.Size = new System.Drawing.Size(32, 17);
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.Name = "textBox_listenPort";
this.textBox_listenPort.Size = new System.Drawing.Size(66, 23);
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(91, 90);
this.comboBox_type.Name = "comboBox_type";
this.comboBox_type.Size = new System.Drawing.Size(121, 25);
this.comboBox_type.TabIndex = 5;
//
// NewProxy
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(339, 128);
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.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "NewProxy";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "NewProxy";
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;
}
}

90
PortProxyGUI/NewProxy.cs Normal file
View File

@ -0,0 +1,90 @@
using 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;
namespace PortProxyGUI
{
public partial class NewProxy : Form
{
public readonly PortProxyGUI PortProxyGUI;
public NewProxy(PortProxyGUI portProxyGUI)
{
PortProxyGUI = portProxyGUI;
InitializeComponent();
}
private void AddPortProxy(string type, string listenPort, string connectTo, string connectPort)
{
var output = CmdRunner.Execute($"netsh interface portproxy add {type} listenport={listenPort} connectaddress={connectTo} connectport={connectPort}");
Invoke((Action)(() => PortProxyGUI.RefreshProxyList()));
}
private void button1_Click(object sender, EventArgs e)
{
var type = comboBox_type.Text;
var connectTo = textBox_connectTo.Text;
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;
}
var 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 ipv6 = connectTo.IsMatch(new Regex(@"^[\dABCDEF]{2}(?::(?:[\dABCDEF]{2})){5}$"));
if (!ipv4 && !ipv6)
{
MessageBox.Show($"The address which is connect to is neither IPv4 nor IPv6.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (ipv4 && !type.EndsWith("v4"))
{
MessageBox.Show($"The type must be v4tov4 or v6tov4.", "Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else if (ipv6 && !type.EndsWith("v6"))
{
MessageBox.Show($"The type must be v4tov6 or v6tov6.", "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);
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;
}
AddPortProxy(type, listenPort, connectTo, connectPort);
}
private void NewProxy_Load(object sender, EventArgs e)
{
}
private void NewProxy_FormClosing(object sender, FormClosingEventArgs e)
{
PortProxyGUI.NewProxyForm = null;
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

20
PortProxyGUI/PortProxy.cs Normal file
View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
namespace PortProxyGUI
{
public class PortProxy
{
public string Type { get; set; }
public string ListenOn { get; set; }
public string ListenPort { get; set; }
public string ConnectTo { get; set; }
public string ConnectPort { get; set; }
}
}

164
PortProxyGUI/PortProxyGUI.Designer.cs generated Normal file
View File

@ -0,0 +1,164 @@
namespace PortProxyGUI
{
partial class PortProxyGUI
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
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.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.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
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.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(460, 230);
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";
this.columnHeader1.Width = 80;
//
// columnHeader2
//
this.columnHeader2.Text = "Listen port";
this.columnHeader2.Width = 100;
//
// columnHeader3
//
this.columnHeader3.Text = "Connect to";
this.columnHeader3.Width = 160;
//
// columnHeader4
//
this.columnHeader4.Text = "Connect port";
this.columnHeader4.Width = 100;
//
// 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";
//
// PortProxyGUI
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(460, 230);
this.Controls.Add(this.listView1);
this.Name = "PortProxyGUI";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "PortProxyGUI";
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;
}
}

View File

@ -0,0 +1,133 @@
using 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;
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<ListViewItem>();
foreach (var item in items)
{
var subItems = item.SubItems.OfType<ListViewSubItem>().ToArray();
var type = subItems[0].Text;
var listenPort = subItems[1].Text;
var output = CmdRunner.Execute($"netsh interface portproxy delete {type} listenport={listenPort}");
}
RefreshProxyList();
}
public void RefreshProxyList()
{
var output = CmdRunner.Execute("netsh interface portproxy show all");
var types = new[] { ("ipv4", "ipv4"), ("ipv4", "ipv6"), ("ipv6", "ipv4"), ("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)
.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(),
},
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.ListenPort, proxy.ConnectTo, proxy.ConnectPort });
}));
}
}
private void contextMenuStrip1_MouseClick(object sender, MouseEventArgs e)
{
if (sender is ContextMenuStrip _sender)
{
var selected = _sender.Items.OfType<ToolStripItem>().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<ListViewItem>().Any())
toolStripMenuItem2.Enabled = true;
else toolStripMenuItem2.Enabled = false;
}
}
}
}

View File

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Authors>zmjack</Authors>
<Company>nstandard.net</Company>
<Description>A manager of the netsh interface portproxy which is to evaluate TCP/IP port redirect on windows.</Description>
<PackageProjectUrl>https://github.com/zmjack/PortProxyGUI</PackageProjectUrl>
<RepositoryUrl>https://github.com/zmjack/PortProxyGUI</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>portproxy TCP/IP redirector</PackageTags>
<PackageLicenseFile>LICENSE.md</PackageLicenseFile>
<Copyright>Copyright © nstandard.net 2020</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NStandard" Version="0.4.6" />
</ItemGroup>
<ItemGroup>
<None Include="..\LICENSE.md">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project>

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

23
PortProxyGUI/Program.cs Normal file
View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PortProxyGUI
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new PortProxyGUI());
}
}
}

76
PortProxyGUI/app.manifest Normal file
View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>