Beispiel #1
0
        public static Rule[] GetProxies()
        {
            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
                                  .ExtractFirst(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 Rule
                    {
                        Type = type.Type,
                        ListenOn = parts[1].First(),
                        ListenPort = int.Parse(parts[2].First()),
                        ConnectTo = parts[3].First(),
                        ConnectPort = int.Parse(parts[4].First()),
                    });
                });
                return(typeProxies ?? new Rule[0]);
            });

            return(proxies.ToArray());
        }
Beispiel #2
0
        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 listenOn   = subItems[1].Text;
                var listenPort = subItems[2].Text;
                var output     = CmdRunner.Execute($"netsh interface portproxy delete {type} listenaddress={listenOn} listenport={listenPort}");
            }
            RefreshProxyList();
        }
Beispiel #3
0
        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 });
                }));
            }
        }
Beispiel #4
0
 public static void DeleteProxy(string type, string listenOn, int listenPort)
 {
     CmdRunner.Execute($"netsh interface portproxy delete {type} listenaddress={listenOn} listenport={listenPort}");
 }
Beispiel #5
0
 public static void AddProxy(string action, string type, string listenOn, int listenPort, string connectTo, int connectPort)
 {
     CmdRunner.Execute($"netsh interface portproxy {action} {type} listenaddress={listenOn} listenport={listenPort} connectaddress={connectTo} connectport={connectPort}");
 }
Beispiel #6
0
        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()));
        }