public void Init(string url, EBrowser browser, Regex regExp, int maxDepth) { _timerStart = Environment.TickCount; _regExp = regExp; _maxDepth = maxDepth; // Set which browser to test _browser = browser; switch (_browser) { case EBrowser.Chrome: _driver = new ChromeDriver(); break; case EBrowser.Firefox: _driver = new FirefoxDriver(); break; case EBrowser.InternetExplorer: _driver = new InternetExplorerDriver(); break; default: _driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript()); break; } // Load root page _driver.Navigate().GoToUrl(url); RootPage = new Page(_driver, null, null) { Source = _driver.PageSource }; #if DEBUG _driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 1)); #else _driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 5)); #endif }
public static IWebDriver CriarWebDriver(EBrowser browser, string caminhoDriver, bool headless) { IWebDriver webDriver = null; switch (browser) { case EBrowser.Chrome: //driver = new ChromeDriver(caminhoDriver, opcoes); ChromeOptions opcoes = new ChromeOptions(); if (headless) { opcoes.AddArgument("--headless"); } webDriver = new ChromeDriver(caminhoDriver, opcoes); break; case EBrowser.Firefox: FirefoxOptions opcoesFF = new FirefoxOptions(); if (headless) { opcoesFF.AddArgument("--headless"); } webDriver = new FirefoxDriver(caminhoDriver, opcoesFF); break; } return(webDriver); }
public static string GetUserAgent(EBrowser browser) { string userAgent = string.Empty; switch (browser) { case EBrowser.Chrome: return("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/ (KHTML, like Gecko) Chrome/"); case EBrowser.Firefox12: return("Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/ Firefox/)"); case EBrowser.IE8: return("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"); case EBrowser.IE9: return("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"); case EBrowser.IE10: return("Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); default: return("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/ (KHTML, like Gecko) Chrome/"); } }
public static void ChangeUserAgent(EBrowser browser) { string userAgent = string.Empty; switch (browser) { case EBrowser.Chrome: userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/ (KHTML, like Gecko) Chrome/"; break; case EBrowser.Firefox12: userAgent = "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/ Firefox/)"; break; case EBrowser.IE8: userAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"; break; case EBrowser.IE9: userAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; break; case EBrowser.IE10: userAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"; break; } UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, userAgent, userAgent.Length, 0); }
public List <string> GetBrowserHistory(EBrowser browser, string historyFile) { SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + historyFile); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; // cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"; // Use the above query to get all the table names cmd.CommandText = "Select * From urls"; SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { //MessageBox.Show(dr[1].ToString()); Console.WriteLine(dr[1].ToString()); } return(null); }
bool parseRequest() { string request; if (!streamReadLine(stream, out request)) return false; string host = ""; string line; bool issocket = false; ESO so = ESO.Unknown; EBrowser br = EBrowser.Unknown; HttpAuth aut = null; Dictionary<string, string> headers = new Dictionary<string, string>(); while (streamReadLine(stream, out line)) { if (string.IsNullOrEmpty(line)) break; string name, val; SeparaEnDos(line, ':', out name, out val); string lname = name.ToLower(); val = val.TrimStart(' '); switch (lname) { case "connection": { if (_Server != null && _Server.AllowKeepAlive) _keep_alive = val.ToLower().Contains("keep-alive"); break; } case "accept-encoding": { _gzip = val.ToLower().Contains("gzip"); break; } case "host": { host = val; break; } case "upgrade": { issocket = val == "websocket"; break; } case "cookie": { string nc, vc; foreach (string s in val.Split(';')) { SeparaEnDos(s, '=', out nc, out vc); nc = HttpUtility.UrlDecode(nc.TrimStart(' ')); vc = HttpUtility.UrlDecode(vc); try { httpCookie.Add(nc, new HttpCookie(nc, vc)); } catch { } } break; } case "authorization": { string tp, vl; SeparaEnDos(val, ' ', out tp, out vl); if (tp.ToLower() == "basic") { byte[] dv = Convert.FromBase64String(vl); vl = codec_iso.GetString(dv); SeparaEnDos(vl, ':', out tp, out vl); aut = new HttpAuth(tp, vl); } break; } case "user-agent": { string tp, vl; SeparaEnDos(val, ' ', out tp, out vl); //SO vl = vl.ToLower(); if (vl.Contains("windows")) so = ESO.Windows; else { if (vl.Contains("android")) so = ESO.Android; else { if (vl.Contains("iphone")) so = ESO.Iphone; else { if (vl.Contains("ipad")) so = ESO.Ipad; else { if (vl.Contains("ipod")) so = ESO.Ipod; else { if (vl.Contains("mac")) so = ESO.Mac; else { if (vl.Contains("linux")) so = ESO.Linux; else { if (vl.Contains("x11")) so = ESO.Unix; } } } } } } } //Browser if (vl.Contains("chrome/")) br = EBrowser.Chrome; else { if (vl.Contains("firefox")) br = EBrowser.FireFox; else { if (vl.Contains("msie")) br = EBrowser.IExplorer; else { if (vl.Contains("konqueror")) br = EBrowser.Konqueror; else { if (vl.Contains("opera/")) br = EBrowser.Opera; else { if (vl.Contains("safari/")) br = EBrowser.Safari; else { tp = tp.ToLower(); if (tp.Contains("dalvik/")) br = EBrowser.Dalvik; } } } } } } break; } } headers.Add(name, val); } _req = new HttpRequest(request, host, _IP, headers, aut, so, br, issocket, _Server.GetAndPostNamesToLowerCase); return true; }
public HttpRequest(string request, string host, string ip, Dictionary <string, string> header, HttpAuth auth, ESO so, EBrowser br, bool is_socket, bool varsToLowerCase) { if (header == null) { http_method = EHttpMethod.Unknown; return; } int ixa = request.IndexOf(' '); if (ixa <= -1) { http_method = EHttpMethod.Unknown; return; } int ixb = request.LastIndexOf(' '); if (ixb <= -1 || ixa == ixb) { http_method = EHttpMethod.Unknown; return; } _VarsToLowerCase = varsToLowerCase; _IP = ip; _so = so; _br = br; _header = header; _auth = auth; _host = new HttpHost(host); switch (request.Substring(0, ixa).ToUpper()) { case "HEAD": http_method = EHttpMethod.HEAD; break; case "GET": http_method = EHttpMethod.GET; break; case "POST": http_method = EHttpMethod.POST; break; default: http_method = EHttpMethod.Unknown; break; } if (is_socket) { http_method = EHttpMethod.SOCKET; } http_url = request.Substring(ixa + 1, ixb - ixa - 1).Trim('/'); http_protocol_version = request.Substring(ixb + 1); int ix_h = http_url.IndexOf('?'); if (ix_h != -1) { foreach (string key in http_url.Remove(0, ix_h + 1).Split('&')) { try { string iz, dr; HttpProcessor.SeparaEnDos(key, '=', out iz, out dr); if (varsToLowerCase) { iz = iz.ToLowerInvariant(); } _get.Add(HttpServer.UrlDecode(iz), HttpServer.UrlDecode(dr)); } catch { } } http_url = http_url.Substring(0, ix_h); } }
public List<string> GetBrowserHistory(EBrowser browser, string historyFile) { SQLiteConnection conn = new SQLiteConnection(@"Data Source=" + historyFile); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.Connection = conn; // cmd.CommandText = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"; // Use the above query to get all the table names cmd.CommandText = "Select * From urls"; SQLiteDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { //MessageBox.Show(dr[1].ToString()); Console.WriteLine(dr[1].ToString()); } return null; }