public static RegProxy GetCurrentProxy() { RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true); bool en = (int)registry.GetValue("ProxyEnable") == 1 ? true : false; string proxy = (string)registry.GetValue("ProxyServer"); return(RegProxy.ParseProxyString(proxy ?? "", en)); }
private void OnProxyStateChanged(RegProxy proxy) { Icon icon = proxy.Enabled ? Resources.proxy_on : Resources.proxy_off; Utility.TryInvoke(this, (Action) delegate { this.Icon = icon; ui_icon.Icon = icon; disconnectToolStripMenuItem.Visible = proxy.Enabled; _connectItem.Enabled = !proxy.Enabled; _disconnectItem.Enabled = proxy.Enabled; ui_Status.Text = proxy.Enabled ? "Proxy running : " + proxy.ToString() : "Currently no proxy running"; ui_icon.Text = ui_Status.Text; ui_ExtraStatus.Text = ""; }); if (proxy.Enabled) { var infos = Functions.GetProxyInfos(proxy); Utility.TryInvoke(this, (Action) delegate { if (infos != null) { var sinfos = new List <string>(); if (!string.IsNullOrEmpty(infos.IP)) { sinfos.Add("IP : " + infos.IP); } if (!string.IsNullOrEmpty(infos.City)) { sinfos.Add("City : " + infos.City); ui_icon.Text += " (" + infos.City + ")"; } if (!string.IsNullOrEmpty(infos.ISP)) { sinfos.Add("ISP : " + infos.ISP); } ui_ExtraStatus.Text = "[ " + String.Join(" | ", sinfos) + " ]"; } }); } }
private void toolStripMenuItem1_Click(object sender, EventArgs e) { var proxy = RegProxy.ParseProxyString(ui_SpecProxy.Text, true); if (!string.IsNullOrEmpty(proxy.IP)) { var infos = Functions.GetProxyInfos(proxy); if (infos != null) { Functions.SetProxy(proxy); } else { MessageBox.Show("Proxy down", "Proxy Me", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Malformed Proxy host & ip", "Proxy Me", MessageBoxButtons.OK, MessageBoxIcon.Error); } }