/// <summary> /// Метод формирования нестандартного прокси из параметров /// </summary> /// <param name="uri"></param> /// <param name="addrDefinition"></param> /// <param name="bypassDefinition"></param> /// <returns></returns> public static WebProxy SelectCustomProxy(Uri uri, string addrDefinition, string bypassDefinition) { var defs = ProxyRecord.Parse(addrDefinition); var def = defs.FirstOrDefault(_ => _.TargetScheme.ToUpperInvariant() == uri.Scheme.ToUpperInvariant()); if (null == def) { def = defs.FirstOrDefault(_ => _.TargetScheme == "*"); } if (null == def) { return(null); } var proxy = new WebProxy( def.Uri, true, null, def.Credentials); if (!string.IsNullOrWhiteSpace(bypassDefinition)) { proxy.BypassList = bypassDefinition.SmartSplit(false, true, ' ').ToArray(); } if (proxy.IsBypassed(uri)) { return(null); } return(proxy); }
public OneProxyControl() { InitializeComponent(); ProxyRecord = new ProxyRecord(); cbProxyProtocol.TextChanged += CbProxyProtocol_TextChanged; cbProxyProtocol.SelectedIndexChanged += CbProxyProtocol_SelectedIndexChanged; tbHost.TextChanged += TbHost_TextChanged; tbPort.TextChanged += TbPort_TextChanged; tbUsername.TextChanged += TbUsername_TextChanged; tbPassword.TextChanged += TbPassword_TextChanged; btnCheckProxy.Click += BtnCheckProxy_Click; }
public void SetProxyRecord(ProxyRecord proxyRecord) { ProxyRecord = proxyRecord.GetCopy(); tbHost.Text = ProxyRecord.Host; tbPort.Text = $"{ProxyRecord.Port}"; if (ProxyRecord.Port == 0) { tbPort.Text = string.Empty; } var proxyProtocol = Enum.GetName(typeof(ProxyProtocol), ProxyRecord.ProxyProtocol).ToLower(); cbProxyProtocol.Text = proxyProtocol; tbUsername.Text = ProxyRecord.Username; tbPassword.Text = ProxyRecord.Password; }
public void DeviceAdded(CpDevice aDevice) { string udn = aDevice.Udn(); Logger.DebugFormat("DeviceAdded: UDN={0}", udn); CountedReference<T> newProxyRef = new CountedReference<T>(iProxyConstructor(aDevice)); aDevice.AddRef(); ProxyRecord newProxyRecord = new ProxyRecord(aDevice, newProxyRef); ProxyRecord oldProxyRecord = null; EventHandler<ProxyEventArgs> handler; lock (iProxiesByUdn) { if (iProxiesByUdn.ContainsKey(udn)) { oldProxyRecord = iProxiesByUdn[udn]; } iProxiesByUdn[aDevice.Udn()] = newProxyRecord; handler = DeviceDetectedHandler; Monitor.PulseAll(iProxiesByUdn); } if (oldProxyRecord != null) { oldProxyRecord.InvokeDisappeared(); oldProxyRecord.Ref.Dispose(); oldProxyRecord.Device.RemoveRef(); } if (handler != null) { handler(this, new ProxyEventArgs(aDevice, newProxyRef, newProxyRecord)); } }
public async Task <Browser> ProfileStart(string chromiumPath, string profilesPath) { if (_browser != null) { return(_browser); } _fingerprint = GetFingerprint(profilesPath); var args = new List <string>(); if (!string.IsNullOrEmpty(UserAgent)) { args.Add($@"--user-agent=""{UserAgent}"""); } if (!string.IsNullOrEmpty(Language)) { args.Add($"--lang={Language}"); } if (RemoteDebuggingPort > 0) { args.Add($"--remote-debugging-port={RemoteDebuggingPort}"); } var proxyArg = ProxyRecord.GetProxyArg(); if (!string.IsNullOrEmpty(proxyArg)) { args.Add(proxyArg); } args.Add("--disable-webgl"); args.Add("--disable-3d-apis"); #region proxy info /* * --proxy-server=host:port * Specify the HTTP/SOCKS4/SOCKS5 proxy server to use for requests. This overrides any environment variables or settings picked via the options dialog. An individual * proxy server is specified using the format: * * [<proxy-scheme>://]<proxy-host>[:<proxy-port>] * * Where <proxy-scheme> is the protocol of the proxy server, and is one of: * * "http", "socks", "socks4", "socks5". * * If the <proxy-scheme> is omitted, it defaults to "http". Also note that "socks" is equivalent to "socks5". * * Examples: * * --proxy-server="foopy:99" * Use the HTTP proxy "foopy:99" to load all URLs. * * --proxy-server="socks://foobar:1080" * Use the SOCKS v5 proxy "foobar:1080" to load all URLs. * * --proxy-server="sock4://foobar:1080" * Use the SOCKS v4 proxy "foobar:1080" to load all URLs. * * --proxy-server="socks5://foobar:66" * Use the SOCKS v5 proxy "foobar:66" to load all URLs. * * It is also possible to specify a separate proxy server for different URL types, by prefixing the proxy server specifier with a URL specifier: * * Example: * * --proxy-server="https=proxy1:80;http=socks4://baz:1080" * Load https://* URLs using the HTTP proxy "proxy1:80". And load http://* * URLs using the SOCKS v4 proxy "baz:1080". */ #endregion var viewPortOptions = new ViewPortOptions { IsLandscape = true }; if (_fingerprint != null) { viewPortOptions = new ViewPortOptions(); viewPortOptions.Height = _fingerprint.height; viewPortOptions.Width = _fingerprint.width; viewPortOptions.DeviceScaleFactor = _fingerprint.attr.windowdevicePixelRatio; args.Add($"--window-size={_fingerprint.width},{_fingerprint.height}"); } var lanchOptions = new LaunchOptions { Headless = false, ExecutablePath = chromiumPath, DefaultViewport = viewPortOptions, IgnoreHTTPSErrors = true, SlowMo = 10, UserDataDir = Path.Combine(profilesPath, Folder), Args = args.ToArray() }; _browser = await Puppeteer.LaunchAsync(lanchOptions); _browser.TargetCreated += Browser_TargetCreated; _browser.TargetChanged += Browser_TargetChanged; _webSocketEndpoint = _browser.WebSocketEndpoint; //await Puppeteer.ConnectAsync(new ConnectOptions()); _browser.Disconnected += Browser_Disconnected; _browser.Closed += Browser_Closed; var page = (await _browser.PagesAsync())[0]; //await page.SetRequestInterceptionAsync(true); //page.Console += Page_Console; //await page.SetViewportAsync(); //await page.SetRequestInterceptionAsync(true); //page.Request += Page_Request; //var headers = new Dictionary<string, string>(); //headers["RtttU"] = " you site"; //headers["Accept"] = "text/html"; //await page.SetExtraHttpHeadersAsync(headers); if (!string.IsNullOrEmpty(proxyArg) && !string.IsNullOrEmpty(ProxyRecord.Username) && !string.IsNullOrEmpty(ProxyRecord.Password)) { await page.AuthenticateAsync(new Credentials { Username = ProxyRecord.Username, Password = ProxyRecord.Password }); } if (!string.IsNullOrEmpty(Timezone)) { await page.EmulateTimezoneAsync(Timezone); } RunScriptOnPage(page); if (!string.IsNullOrEmpty(StartUrl)) { await page.GoToAsync(StartUrl, _navigationOptions); } //var session = await page.Target.CreateCDPSessionAsync(); //await session.SendAsync("Emulation.setPageScaleFactor", new { pageScaleFactor= 4 }); return(_browser); }
public BrowserProfile() { ProxyRecord = new ProxyRecord(); RemoteDebuggingPort = 0; }